<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha256-CTSx/A06dm1B063156EVh15m6Y67pAjZZaQc89LLSrU=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.css" integrity="sha256-vQkngPS8jiHHH0I6ABTZroZk8NPZ7b+MUReOFE9UsXQ=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"rjyblog.gitee.io","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.18.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":null},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta property="og:type" content="website">
<meta property="og:title" content="任建勇的博客">
<meta property="og:url" content="https://rjyblog.gitee.io/page/3/index.html">
<meta property="og:site_name" content="任建勇的博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="Jason">
<meta property="article:tag" content="Android, Java, Kotlin, Flutter, 前端技术, 设计模式">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://rjyblog.gitee.io/page/3/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":true,"isPost":false,"lang":"zh-CN","comments":"","permalink":"","path":"page/3/index.html","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>任建勇的博客</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">任建勇的博客</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Jason"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">Jason</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">66</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">13</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/2230f1f1.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/2230f1f1.html" class="post-title-link" itemprop="url">Java float和double存储结构</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-17 14:19:09" itemprop="dateCreated datePublished" datetime="2023-09-17T14:19:09+08:00">2023-09-17</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-19 15:02:52" itemprop="dateModified" datetime="2023-10-19T15:02:52+08:00">2023-10-19</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">Java float和double存储结构</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p><img src="/images/Java%E6%B5%AE%E7%82%B9%E6%95%B0%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84.drawio.svg" alt="Java浮点数存储结构"></p>
<h2 id="浮点数转换二进制"><a href="#浮点数转换二进制" class="headerlink" title="浮点数转换二进制"></a>浮点数转换二进制</h2><p>以<code>18.725</code>为例进行说明。</p>
<p><strong>整数部分转二进制</strong>：除2取余法。整数部分除以2取余数，商取整继续除以2取余数，直到商为0。</p>
<table>
<thead>
<tr>
<th>整数除法</th>
<th>商</th>
<th>余数</th>
</tr>
</thead>
<tbody><tr>
<td>$18/2$</td>
<td>9</td>
<td>0</td>
</tr>
<tr>
<td>$9/2$</td>
<td>4</td>
<td>1</td>
</tr>
<tr>
<td>$4/2$</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td>$2/2$</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td>$1/2$</td>
<td>0</td>
<td>1</td>
</tr>
</tbody></table>
<p>18转换为二进制就是<code>10010</code>，上面表格中余数的倒序。</p>
<p><strong>小数部分转二进制</strong>：乘2取整法。小数部分乘以2，取整数部分，剩下的小数部分继续乘以2取整数部分，直到结果为0。如果永远不为零，则到达期望的精度后终止运算。</p>
<table>
<thead>
<tr>
<th>乘法公式</th>
<th>小数部分</th>
<th>整数部分</th>
</tr>
</thead>
<tbody><tr>
<td>$0.725*2=1.45$</td>
<td>0.45</td>
<td>1</td>
</tr>
<tr>
<td>$0.45*2=0.9$</td>
<td>0.9</td>
<td>0</td>
</tr>
<tr>
<td>$0.9*2=1.8$</td>
<td>0.8</td>
<td>1</td>
</tr>
<tr>
<td>$0.8*2=1.6$</td>
<td>0.6</td>
<td>1</td>
</tr>
<tr>
<td>$0.6*2=1.2$</td>
<td>0.2</td>
<td>1</td>
</tr>
<tr>
<td>$0.2*2=0.4$</td>
<td>0.4</td>
<td>0</td>
</tr>
<tr>
<td>$0.4*2=0.8$</td>
<td>0.8</td>
<td>0</td>
</tr>
<tr>
<td>$0.8*2=1.6$</td>
<td>0.6</td>
<td>1</td>
</tr>
<tr>
<td>$0.6*2=1.2$</td>
<td>0.2</td>
<td>1</td>
</tr>
<tr>
<td>$0.2*2=0.4$</td>
<td>0.4</td>
<td>0</td>
</tr>
<tr>
<td>……</td>
<td>……</td>
<td>……</td>
</tr>
</tbody></table>
<p>0.725的二进制数是<code>0.1011100110</code>（后面还有无限长，这里忽略）。所以18.725的二级制就是<code>10010.1011100110</code>。按照规定，二进制小数点左边只能有1为且固定为1，所以需要进行右移操作，得出结果是：$1.00101011100110*2^4$</p>
<ul>
<li>符号位：正数，符号位为0；</li>
<li>指数位：实际为4，按照规定要加上127（即指数最高位赋值为1），指数位存储的是131，二级制为<code>10000011</code>，。</li>
<li>底数位：取小数部分，即 <code>0.00101011100110</code>；</li>
</ul>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/2230f1f1.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/ca4438af.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/ca4438af.html" class="post-title-link" itemprop="url">HashMap源码分析</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-16 16:05:07" itemprop="dateCreated datePublished" datetime="2023-09-16T16:05:07+08:00">2023-09-16</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 16:16:24" itemprop="dateModified" datetime="2023-10-18T16:16:24+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">HashMap源码分析</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>HashMap存储结构采用数组+链表<small>（java8以后当链表长度超过8后采用红黑树来存储）</small>，当存储数据时会先计算key的哈希值，然后使用哈希值计算数组指针，如果数组指针位置已经存在数据，且key不相同，就会采用链表形式存储数据。存储结构如下图：</p>
<p><img src="/images/HashMap%E5%AD%98%E5%82%A8%E7%BB%93%E6%9E%84.drawio.svg" alt="HashMap存储结构"></p>
<p>在jdk1.8中HashMap引入了红黑树，当链表中的元素达到阈值后，并且数组长度大于64，就会将链表转换为红黑树。引入红黑树的主要目的是解决哈希冲突导致的链化严重的问题。</p>
<h2 id="哈希值与数组指针"><a href="#哈希值与数组指针" class="headerlink" title="哈希值与数组指针"></a>哈希值与数组指针</h2><p>哈希值计算方法：获取key的hashCode，然后hashCode右移16位，最后将两者进行异或运算。源码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">static</span> <span class="keyword">final</span> <span class="type">int</span> <span class="title function_">hash</span><span class="params">(Object key)</span> &#123;</span><br><span class="line">    <span class="type">int</span> h;</span><br><span class="line">    <span class="keyword">return</span> (key == <span class="literal">null</span>) ? <span class="number">0</span> : (h = key.hashCode()) ^ (h &gt;&gt;&gt; <span class="number">16</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>为什么没有直接使用key.hashCode()的值呢？这是因为数组长度都是2的幕，比如默认数组长度16=$2^4$，即<code>1&lt;&lt;4</code>，长度掩码就是<code>15=16-1</code>，二进制掩码就是<code>1111</code>。hash与掩码进行按位与运算后得到数组指针，相当于只取了hash的低4位，高位没有用到，增加了指针冲突的概率。因此将hashCode进行右移16位，再进行异或运算，这样做就是在运算中同时使用了高位和低位。</p>
<p>HashMap是通过数组来存储元素。当通过key来后去元素值的时候，首先计算出key的哈希值，然后通过哈希值来计算得到数组坐标，看下put操作中如何计算数组坐标：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">final</span> V <span class="title function_">putVal</span><span class="params">(<span class="type">int</span> hash, K key, V value, <span class="type">boolean</span> onlyIfAbsent,</span></span><br><span class="line"><span class="params">               <span class="type">boolean</span> evict)</span> &#123;</span><br><span class="line">    Node&lt;K,V&gt;[] tab; Node&lt;K,V&gt; p; <span class="type">int</span> n, i;</span><br><span class="line">    <span class="keyword">if</span> ((tab = table) == <span class="literal">null</span> || (n = tab.length) == <span class="number">0</span>)</span><br><span class="line">        n = (tab = resize()).length;</span><br><span class="line">    <span class="keyword">if</span> ((p = tab[i = (n - <span class="number">1</span>) &amp; hash]) == <span class="literal">null</span>)  <span class="comment">//从数组中取出node赋值给p</span></span><br><span class="line">        tab[i] = newNode(hash, key, value, <span class="literal">null</span>);</span><br><span class="line">    ......</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>从代码中可以看出，计算数组坐标的算法是：<code>(n - 1) &amp; hash</code>，其中<code>n</code>表示数组长度。所以坐标指针是hash和长度掩码进行与运算。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/ca4438af.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/23659d3d.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/23659d3d.html" class="post-title-link" itemprop="url">ARouter源码分析</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-14 17:23:33" itemprop="dateCreated datePublished" datetime="2023-09-14T17:23:33+08:00">2023-09-14</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 09:34:04" itemprop="dateModified" datetime="2023-10-18T09:34:04+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">ARouter源码分析</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="初始化"><a href="#初始化" class="headerlink" title="初始化"></a>初始化</h2><?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="70px" preserveAspectRatio="none" style="width:247px;height:70px;background:#FFFFFF;" version="1.1" viewBox="0 0 247 70" width="247px" zoomAndPan="magnify"><defs/><g><!--class ARouter--><g id="elem_ARouter"><rect codeline="1" fill="#F1F1F1" height="56.2656" id="ARouter" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="99" x="7" y="7"/><ellipse cx="22" cy="27.1328" fill="#FF7700" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M25.7813,23.1016 C25.7813,22.6641 25.7656,22.5234 25.6719,22.3672 C25.5313,22.1328 25.25,21.9766 24.9531,21.9766 C24.6094,21.9766 24.4688,22.1172 24.2969,22.5391 C23.7031,22.1641 22.9531,21.9766 22.0781,21.9766 C19.9688,21.9766 18.3906,23.2734 18.3906,24.9922 C18.3906,25.9609 18.9219,26.8672 19.7813,27.3516 C20.3281,27.6641 20.875,27.8359 21.9844,28.0234 C23.1406,28.2266 23.4063,28.2891 23.7656,28.4766 C24.1406,28.6797 24.375,29.0234 24.375,29.3828 C24.375,30.1172 23.3906,30.6641 22.1406,30.6641 C21.0156,30.6641 19.9375,30.1797 19.7656,29.5703 C19.6406,29.1016 19.6406,29.1016 19.5156,28.9922 C19.3594,28.8359 19.1406,28.7422 18.9063,28.7422 C18.625,28.7422 18.375,28.8672 18.2031,29.0859 C18.0938,29.2578 18.0469,29.4453 18.0469,29.8672 L18.0469,30.9922 C18.0469,31.7578 18.3281,32.1172 18.9219,32.1172 C19.1875,32.1172 19.3125,32.0547 19.5938,31.7109 C20.4375,32.1484 21.3281,32.3672 22.25,32.3672 C24.5781,32.3672 26.1406,31.1797 26.1406,29.4141 C26.1406,28.5234 25.8281,27.8359 25.1406,27.2891 C24.6094,26.8672 23.9688,26.6172 22.4844,26.3516 C21.2188,26.1172 21.125,26.0859 20.7969,25.9141 C20.4219,25.7266 20.1563,25.3359 20.1563,24.9766 C20.1563,24.2422 21.0156,23.6797 22.0781,23.6797 C23.1406,23.6797 23.9531,24.1484 24.1094,24.8203 C24.2188,25.3672 24.2188,25.3672 24.3438,25.5078 C24.4844,25.6328 24.7188,25.7422 24.9531,25.7422 C25.2188,25.7422 25.4688,25.6016 25.6406,25.3828 C25.75,25.2109 25.7813,25.0703 25.7813,24.6016 L25.7813,23.1016 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="71" x="34" y="23.1387">&#171;Singleton&#187;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="59" x="40" y="38.9639">ARouter</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="105" y1="47.2656" y2="47.2656"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="105" y1="55.2656" y2="55.2656"/></g><!--class _ARouter--><g id="elem__ARouter"><rect codeline="2" fill="#F1F1F1" height="56.2656" id="_ARouter" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="99" x="141" y="7"/><ellipse cx="156" cy="27.1328" fill="#FF7700" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M159.7813,23.1016 C159.7813,22.6641 159.7656,22.5234 159.6719,22.3672 C159.5313,22.1328 159.25,21.9766 158.9531,21.9766 C158.6094,21.9766 158.4688,22.1172 158.2969,22.5391 C157.7031,22.1641 156.9531,21.9766 156.0781,21.9766 C153.9688,21.9766 152.3906,23.2734 152.3906,24.9922 C152.3906,25.9609 152.9219,26.8672 153.7813,27.3516 C154.3281,27.6641 154.875,27.8359 155.9844,28.0234 C157.1406,28.2266 157.4063,28.2891 157.7656,28.4766 C158.1406,28.6797 158.375,29.0234 158.375,29.3828 C158.375,30.1172 157.3906,30.6641 156.1406,30.6641 C155.0156,30.6641 153.9375,30.1797 153.7656,29.5703 C153.6406,29.1016 153.6406,29.1016 153.5156,28.9922 C153.3594,28.8359 153.1406,28.7422 152.9063,28.7422 C152.625,28.7422 152.375,28.8672 152.2031,29.0859 C152.0938,29.2578 152.0469,29.4453 152.0469,29.8672 L152.0469,30.9922 C152.0469,31.7578 152.3281,32.1172 152.9219,32.1172 C153.1875,32.1172 153.3125,32.0547 153.5938,31.7109 C154.4375,32.1484 155.3281,32.3672 156.25,32.3672 C158.5781,32.3672 160.1406,31.1797 160.1406,29.4141 C160.1406,28.5234 159.8281,27.8359 159.1406,27.2891 C158.6094,26.8672 157.9688,26.6172 156.4844,26.3516 C155.2188,26.1172 155.125,26.0859 154.7969,25.9141 C154.4219,25.7266 154.1563,25.3359 154.1563,24.9766 C154.1563,24.2422 155.0156,23.6797 156.0781,23.6797 C157.1406,23.6797 157.9531,24.1484 158.1094,24.8203 C158.2188,25.3672 158.2188,25.3672 158.3438,25.5078 C158.4844,25.6328 158.7188,25.7422 158.9531,25.7422 C159.2188,25.7422 159.4688,25.6016 159.6406,25.3828 C159.75,25.2109 159.7813,25.0703 159.7813,24.6016 L159.7813,23.1016 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="71" x="168" y="23.1387">&#171;Singleton&#187;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="66" x="170.5" y="38.9639">_ARouter</text><line style="stroke:#181818;stroke-width:0.5;" x1="142" x2="239" y1="47.2656" y2="47.2656"/><line style="stroke:#181818;stroke-width:0.5;" x1="142" x2="239" y1="55.2656" y2="55.2656"/></g><!--link ARouter to _ARouter--><g id="link_ARouter__ARouter"><path codeline="3" d="M106.2266,35 C117.748,35 123.27,35 134.792,35 " fill="none" id="ARouter-to-_ARouter" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="140.792,35,131.792,31,135.792,35,131.792,39,140.792,35" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[Iyv9B2vMS0pABor9BLAmiL7G2DPHTdCpDpSmq5G8pinBpqajoSzJiBFZIWQhZ2T6AKoDhXrSFG00]--></g></svg>

<p>初始化调用时序</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="250px" preserveAspectRatio="none" style="width:366px;height:250px;background:#FFFFFF;" version="1.1" viewBox="0 0 366 250" width="366px" zoomAndPan="magnify"><defs/><g><rect fill="#FFFFFF" height="138.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="46" y="67.4297"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="132.5" y="96.5625"/><rect fill="#FFFFFF" height="80.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="246" y="125.6953"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="50.5" x2="50.5" y1="36.2969" y2="214.9609"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="137.5" x2="137.5" y1="36.2969" y2="214.9609"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="250.5" x2="250.5" y1="36.2969" y2="214.9609"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="73" x="14.5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="59" x="21.5" y="24.9951">ARouter</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="73" x="14.5" y="213.9609"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="59" x="21.5" y="233.9561">ARouter</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="80" x="97.5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="66" x="104.5" y="24.9951">_ARouter</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="80" x="97.5" y="213.9609"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="66" x="104.5" y="233.9561">_ARouter</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="127" x="187.5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="113" x="194.5" y="24.9951">LogisticsCenter</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="127" x="187.5" y="213.9609"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="113" x="194.5" y="233.9561">LogisticsCenter</text><rect fill="#FFFFFF" height="138.5313" style="stroke:#181818;stroke-width:1.0;" width="10" x="46" y="67.4297"/><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="132.5" y="96.5625"/><rect fill="#FFFFFF" height="80.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="246" y="125.6953"/><ellipse cx="7.5" cy="66.6797" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="34,63.4297,44,67.4297,34,71.4297,38,67.4297" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="40" y1="67.4297" y2="67.4297"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="19" x="15" y="62.3638">init</text><polygon fill="#181818" points="120.5,92.5625,130.5,96.5625,120.5,100.5625,124.5,96.5625" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="56" x2="126.5" y1="96.5625" y2="96.5625"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="19" x="63" y="91.4966">init</text><polygon fill="#181818" points="234,121.6953,244,125.6953,234,129.6953,238,125.6953" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="137.5" x2="240" y1="125.6953" y2="125.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="19" x="144.5" y="120.6294">init</text><line style="stroke:#181818;stroke-width:1.0;" x1="256" x2="298" y1="154.8281" y2="154.8281"/><line style="stroke:#181818;stroke-width:1.0;" x1="298" x2="298" y1="154.8281" y2="167.8281"/><line style="stroke:#181818;stroke-width:1.0;" x1="257" x2="298" y1="167.8281" y2="167.8281"/><polygon fill="#181818" points="267,163.8281,257,167.8281,267,171.8281,263,167.8281" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="96" x="263" y="149.7622">loadRouterMap</text><polygon fill="#181818" points="125.5,192.9609,135.5,196.9609,125.5,200.9609,129.5,196.9609" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="56" x2="131.5" y1="196.9609" y2="196.9609"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="50" x="63" y="191.895">afterInit</text><!--SRC=[YyxNjLDm3CelBKajKj3MjbB8pCiiuO890ENYCIJZaMHzyjCpYqioaukTK_F0GhfmPHXIcAgj57Bo4rCWflac5c2praeXCGr8UG9D1000]--></g></svg>

<h2 id="生成路由表"><a href="#生成路由表" class="headerlink" title="生成路由表"></a>生成路由表</h2><p>ARouter是通过在编译阶段使用<a target="_blank" rel="noopener external nofollow noreferrer" href="https://kotlinlang.org/docs/kapt.html">kapt</a>解析Route注解，再通过<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/square/javapoet">javapoet</a>来生成路由表相关代码。注解处理器在<code>arouter-compiler/src/main/java/com/alibaba/android/arouter/compiler/processor/RouteProcessor.java</code>。</p>
<p>比如<code>module-kotlin</code>模块有三个activity，路由分别是：</p>
<ul>
<li>/one/first</li>
<li>/one/second</li>
<li>/two/test</li>
</ul>
<p>生成的路由表如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//生成目录位于module-kotlin/build/generated/source/kapt/debug/com/alibaba/android/arouter/routes</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ARouter$$Root$$modulekotlin</span> <span class="keyword">implements</span> <span class="title class_">IRouteRoot</span> &#123;</span><br><span class="line">  <span class="meta">@Override</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">loadInto</span><span class="params">(Map&lt;String, Class&lt;? extends IRouteGroup&gt;&gt; routes)</span> &#123;</span><br><span class="line">    routes.put(<span class="string">&quot;one&quot;</span>, ARouter$$Group$$one.class);</span><br><span class="line">    routes.put(<span class="string">&quot;two&quot;</span>, ARouter$$Group$$two.class);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ARouter$$Group$$one</span> <span class="keyword">implements</span> <span class="title class_">IRouteGroup</span> &#123;</span><br><span class="line">  <span class="meta">@Override</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">loadInto</span><span class="params">(Map&lt;String, RouteMeta&gt; atlas)</span> &#123;</span><br><span class="line">    atlas.put(<span class="string">&quot;/one/first&quot;</span>, RouteMeta.build(RouteType.ACTIVITY, FistActivity.class, <span class="string">&quot;/one/first&quot;</span>, <span class="string">&quot;one&quot;</span>, <span class="literal">null</span>, -<span class="number">1</span>, -<span class="number">2147483648</span>));</span><br><span class="line">    atlas.put(<span class="string">&quot;/one/second&quot;</span>, RouteMeta.build(RouteType.ACTIVITY, SecondActivity.class, <span class="string">&quot;/one/second&quot;</span>, <span class="string">&quot;two&quot;</span>, <span class="literal">null</span>, -<span class="number">1</span>, -<span class="number">2147483648</span>));</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ARouter$$Group$$two</span> <span class="keyword">implements</span> <span class="title class_">IRouteGroup</span> &#123;</span><br><span class="line">  <span class="meta">@Override</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">loadInto</span><span class="params">(Map&lt;String, RouteMeta&gt; atlas)</span> &#123;</span><br><span class="line">    atlas.put(<span class="string">&quot;/two/test&quot;</span>, RouteMeta.build(RouteType.ACTIVITY, TestActivity.class, <span class="string">&quot;/two/test&quot;</span>, <span class="string">&quot;two&quot;</span>, <span class="literal">null</span>, -<span class="number">1</span>, -<span class="number">2147483648</span>));</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/23659d3d.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/faedbb97.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/faedbb97.html" class="post-title-link" itemprop="url">LeakCanary源码详解</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-12 15:27:58" itemprop="dateCreated datePublished" datetime="2023-09-12T15:27:58+08:00">2023-09-12</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 10:25:18" itemprop="dateModified" datetime="2023-10-18T10:25:18+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">LeakCanary源码详解</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>本文基于LeakCanary 2.12进行分析。</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="635px" preserveAspectRatio="none" style="width:893px;height:635px;background:#FFFFFF;" version="1.1" viewBox="0 0 893 635" width="893px" zoomAndPan="magnify"><defs/><g><!--cluster Application--><g id="cluster_Application"><path d="M8.5,296 L102.5,296 A3.75,3.75 0 0 1 105,298.5 L112,318.2969 L251.5,318.2969 A2.5,2.5 0 0 1 254,320.7969 L254,392.5 A2.5,2.5 0 0 1 251.5,395 L8.5,395 A2.5,2.5 0 0 1 6,392.5 L6,298.5 A2.5,2.5 0 0 1 8.5,296 " fill="none" style="stroke:#000000;stroke-width:1.5;"/><line style="stroke:#000000;stroke-width:1.5;" x1="6" x2="112" y1="318.2969" y2="318.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacing" textLength="93" x="10" y="310.9951">Application</text></g><!--class ActivityLifecycleCallbacks--><g id="elem_ActivityLifecycleCallbacks"><rect codeline="21" fill="#F1F1F1" height="48" id="ActivityLifecycleCallbacks" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="215" x="22.5" y="331"/><ellipse cx="37.5" cy="347" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M38.4531,343.7813 L40.1719,343.7813 C40.5625,343.7813 40.75,343.75 40.875,343.6719 C41.1406,343.5156 41.2813,343.2344 41.2813,342.9375 C41.2813,342.6719 41.1719,342.4063 40.9375,342.2344 C40.7656,342.125 40.625,342.0938 40.1719,342.0938 L35.0313,342.0938 C34.5938,342.0938 34.4688,342.1094 34.3125,342.2031 C34.0625,342.3594 33.9063,342.6563 33.9063,342.9375 C33.9063,343.2188 34.0469,343.4688 34.2656,343.6406 C34.4219,343.75 34.6094,343.7813 35.0313,343.7813 L36.75,343.7813 L36.75,350.2969 L35.0313,350.2969 C34.5938,350.2969 34.4688,350.3125 34.3125,350.4219 C34.0625,350.5781 33.9063,350.8594 33.9063,351.1563 C33.9063,351.4063 34.0469,351.6719 34.2656,351.8281 C34.4219,351.9531 34.625,352 35.0313,352 L40.1719,352 C40.9219,352 41.2813,351.7188 41.2813,351.1563 C41.2813,350.875 41.1719,350.625 40.9375,350.4531 C40.7656,350.3281 40.625,350.2969 40.1719,350.2969 L38.4531,350.2969 L38.4531,343.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="183" x="51.5" y="351.8467">ActivityLifecycleCallbacks</text><line style="stroke:#181818;stroke-width:0.5;" x1="23.5" x2="236.5" y1="363" y2="363"/><line style="stroke:#181818;stroke-width:0.5;" x1="23.5" x2="236.5" y1="371" y2="371"/></g><!--class ReachabilityWatcher--><g id="elem_ReachabilityWatcher"><rect codeline="1" fill="#F1F1F1" height="48" id="ReachabilityWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="180" x="369" y="331"/><ellipse cx="384" cy="347" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M384.9531,343.7813 L386.6719,343.7813 C387.0625,343.7813 387.25,343.75 387.375,343.6719 C387.6406,343.5156 387.7813,343.2344 387.7813,342.9375 C387.7813,342.6719 387.6719,342.4063 387.4375,342.2344 C387.2656,342.125 387.125,342.0938 386.6719,342.0938 L381.5313,342.0938 C381.0938,342.0938 380.9688,342.1094 380.8125,342.2031 C380.5625,342.3594 380.4063,342.6563 380.4063,342.9375 C380.4063,343.2188 380.5469,343.4688 380.7656,343.6406 C380.9219,343.75 381.1094,343.7813 381.5313,343.7813 L383.25,343.7813 L383.25,350.2969 L381.5313,350.2969 C381.0938,350.2969 380.9688,350.3125 380.8125,350.4219 C380.5625,350.5781 380.4063,350.8594 380.4063,351.1563 C380.4063,351.4063 380.5469,351.6719 380.7656,351.8281 C380.9219,351.9531 381.125,352 381.5313,352 L386.6719,352 C387.4219,352 387.7813,351.7188 387.7813,351.1563 C387.7813,350.875 387.6719,350.625 387.4375,350.4531 C387.2656,350.3281 387.125,350.2969 386.6719,350.2969 L384.9531,350.2969 L384.9531,343.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="148" x="398" y="351.8467">ReachabilityWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="370" x2="548" y1="363" y2="363"/><line style="stroke:#181818;stroke-width:0.5;" x1="370" x2="548" y1="371" y2="371"/></g><!--class ObjectWatcher--><g id="elem_ObjectWatcher"><rect codeline="3" fill="#F1F1F1" height="80.5938" id="ObjectWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="406" x="256" y="439"/><ellipse cx="399.75" cy="455" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M402.0938,450.6719 C401.1563,450.2344 400.5625,450.0938 399.6875,450.0938 C397.0625,450.0938 395.0625,452.1719 395.0625,454.8906 L395.0625,456.0156 C395.0625,458.5938 397.1719,460.4844 400.0625,460.4844 C401.2813,460.4844 402.4375,460.1875 403.1875,459.6406 C403.7656,459.2344 404.0938,458.7813 404.0938,458.3906 C404.0938,457.9375 403.7031,457.5469 403.2344,457.5469 C403.0156,457.5469 402.8125,457.625 402.625,457.8125 C402.1719,458.2969 402.1719,458.2969 401.9844,458.3906 C401.5625,458.6563 400.875,458.7813 400.1094,458.7813 C398.0625,458.7813 396.7656,457.6875 396.7656,455.9844 L396.7656,454.8906 C396.7656,453.1094 398.0156,451.7969 399.75,451.7969 C400.3281,451.7969 400.9375,451.9531 401.4063,452.2031 C401.8906,452.4844 402.0625,452.7031 402.1563,453.1094 C402.2188,453.5156 402.25,453.6406 402.3906,453.7656 C402.5313,453.9063 402.7656,454.0156 402.9844,454.0156 C403.25,454.0156 403.5156,453.875 403.6875,453.6563 C403.7969,453.5 403.8281,453.3125 403.8281,452.8906 L403.8281,451.4688 C403.8281,451.0313 403.8125,450.9063 403.7188,450.75 C403.5625,450.4844 403.2813,450.3438 402.9844,450.3438 C402.6875,450.3438 402.4844,450.4375 402.2656,450.75 L402.0938,450.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="110" x="420.25" y="459.8467">ObjectWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="257" x2="661" y1="471" y2="471"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="394" x="262" y="487.9951">watchedObjects : Map&lt;String, KeyedWeakReference&gt;</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="225" x="262" y="504.292">queue : ReferenceQueue&lt;Any&gt;</text><line style="stroke:#181818;stroke-width:0.5;" x1="257" x2="661" y1="511.5938" y2="511.5938"/></g><!--class KeyedWeakReference--><g id="elem_KeyedWeakReference"><rect fill="#F1F1F1" height="48" id="KeyedWeakReference" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="192" x="519" y="580"/><ellipse cx="534" cy="596" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M536.3438,591.6719 C535.4063,591.2344 534.8125,591.0938 533.9375,591.0938 C531.3125,591.0938 529.3125,593.1719 529.3125,595.8906 L529.3125,597.0156 C529.3125,599.5938 531.4219,601.4844 534.3125,601.4844 C535.5313,601.4844 536.6875,601.1875 537.4375,600.6406 C538.0156,600.2344 538.3438,599.7813 538.3438,599.3906 C538.3438,598.9375 537.9531,598.5469 537.4844,598.5469 C537.2656,598.5469 537.0625,598.625 536.875,598.8125 C536.4219,599.2969 536.4219,599.2969 536.2344,599.3906 C535.8125,599.6563 535.125,599.7813 534.3594,599.7813 C532.3125,599.7813 531.0156,598.6875 531.0156,596.9844 L531.0156,595.8906 C531.0156,594.1094 532.2656,592.7969 534,592.7969 C534.5781,592.7969 535.1875,592.9531 535.6563,593.2031 C536.1406,593.4844 536.3125,593.7031 536.4063,594.1094 C536.4688,594.5156 536.5,594.6406 536.6406,594.7656 C536.7813,594.9063 537.0156,595.0156 537.2344,595.0156 C537.5,595.0156 537.7656,594.875 537.9375,594.6563 C538.0469,594.5 538.0781,594.3125 538.0781,593.8906 L538.0781,592.4688 C538.0781,592.0313 538.0625,591.9063 537.9688,591.75 C537.8125,591.4844 537.5313,591.3438 537.2344,591.3438 C536.9375,591.3438 536.7344,591.4375 536.5156,591.75 L536.3438,591.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="160" x="548" y="600.8467">KeyedWeakReference</text><line style="stroke:#181818;stroke-width:0.5;" x1="520" x2="710" y1="612" y2="612"/><line style="stroke:#181818;stroke-width:0.5;" x1="520" x2="710" y1="620" y2="620"/></g><!--class WeakReference--><g id="elem_WeakReference"><rect fill="#F1F1F1" height="48" id="WeakReference" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="147" x="697.5" y="455.5"/><ellipse cx="712.5" cy="471.5" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M714.8438,467.1719 C713.9063,466.7344 713.3125,466.5938 712.4375,466.5938 C709.8125,466.5938 707.8125,468.6719 707.8125,471.3906 L707.8125,472.5156 C707.8125,475.0938 709.9219,476.9844 712.8125,476.9844 C714.0313,476.9844 715.1875,476.6875 715.9375,476.1406 C716.5156,475.7344 716.8438,475.2813 716.8438,474.8906 C716.8438,474.4375 716.4531,474.0469 715.9844,474.0469 C715.7656,474.0469 715.5625,474.125 715.375,474.3125 C714.9219,474.7969 714.9219,474.7969 714.7344,474.8906 C714.3125,475.1563 713.625,475.2813 712.8594,475.2813 C710.8125,475.2813 709.5156,474.1875 709.5156,472.4844 L709.5156,471.3906 C709.5156,469.6094 710.7656,468.2969 712.5,468.2969 C713.0781,468.2969 713.6875,468.4531 714.1563,468.7031 C714.6406,468.9844 714.8125,469.2031 714.9063,469.6094 C714.9688,470.0156 715,470.1406 715.1406,470.2656 C715.2813,470.4063 715.5156,470.5156 715.7344,470.5156 C716,470.5156 716.2656,470.375 716.4375,470.1563 C716.5469,470 716.5781,469.8125 716.5781,469.3906 L716.5781,467.9688 C716.5781,467.5313 716.5625,467.4063 716.4688,467.25 C716.3125,466.9844 716.0313,466.8438 715.7344,466.8438 C715.4375,466.8438 715.2344,466.9375 715.0156,467.25 L714.8438,467.1719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="115" x="726.5" y="476.3467">WeakReference</text><line style="stroke:#181818;stroke-width:0.5;" x1="698.5" x2="843.5" y1="487.5" y2="487.5"/><line style="stroke:#181818;stroke-width:0.5;" x1="698.5" x2="843.5" y1="495.5" y2="495.5"/></g><!--class InstallableWatcher--><g id="elem_InstallableWatcher"><rect codeline="10" fill="#F1F1F1" height="48" id="InstallableWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="165" x="351.5" y="115"/><ellipse cx="366.5" cy="131" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M367.4531,127.7813 L369.1719,127.7813 C369.5625,127.7813 369.75,127.75 369.875,127.6719 C370.1406,127.5156 370.2813,127.2344 370.2813,126.9375 C370.2813,126.6719 370.1719,126.4063 369.9375,126.2344 C369.7656,126.125 369.625,126.0938 369.1719,126.0938 L364.0313,126.0938 C363.5938,126.0938 363.4688,126.1094 363.3125,126.2031 C363.0625,126.3594 362.9063,126.6563 362.9063,126.9375 C362.9063,127.2188 363.0469,127.4688 363.2656,127.6406 C363.4219,127.75 363.6094,127.7813 364.0313,127.7813 L365.75,127.7813 L365.75,134.2969 L364.0313,134.2969 C363.5938,134.2969 363.4688,134.3125 363.3125,134.4219 C363.0625,134.5781 362.9063,134.8594 362.9063,135.1563 C362.9063,135.4063 363.0469,135.6719 363.2656,135.8281 C363.4219,135.9531 363.625,136 364.0313,136 L369.1719,136 C369.9219,136 370.2813,135.7188 370.2813,135.1563 C370.2813,134.875 370.1719,134.625 369.9375,134.4531 C369.7656,134.3281 369.625,134.2969 369.1719,134.2969 L367.4531,134.2969 L367.4531,127.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="133" x="380.5" y="135.8467">InstallableWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="352.5" x2="515.5" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="352.5" x2="515.5" y1="155" y2="155"/></g><!--class ActivityWatcher--><g id="elem_ActivityWatcher"><rect fill="#F1F1F1" height="48" id="ActivityWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="149" x="55.5" y="223"/><ellipse cx="70.5" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M72.8438,234.6719 C71.9063,234.2344 71.3125,234.0938 70.4375,234.0938 C67.8125,234.0938 65.8125,236.1719 65.8125,238.8906 L65.8125,240.0156 C65.8125,242.5938 67.9219,244.4844 70.8125,244.4844 C72.0313,244.4844 73.1875,244.1875 73.9375,243.6406 C74.5156,243.2344 74.8438,242.7813 74.8438,242.3906 C74.8438,241.9375 74.4531,241.5469 73.9844,241.5469 C73.7656,241.5469 73.5625,241.625 73.375,241.8125 C72.9219,242.2969 72.9219,242.2969 72.7344,242.3906 C72.3125,242.6563 71.625,242.7813 70.8594,242.7813 C68.8125,242.7813 67.5156,241.6875 67.5156,239.9844 L67.5156,238.8906 C67.5156,237.1094 68.7656,235.7969 70.5,235.7969 C71.0781,235.7969 71.6875,235.9531 72.1563,236.2031 C72.6406,236.4844 72.8125,236.7031 72.9063,237.1094 C72.9688,237.5156 73,237.6406 73.1406,237.7656 C73.2813,237.9063 73.5156,238.0156 73.7344,238.0156 C74,238.0156 74.2656,237.875 74.4375,237.6563 C74.5469,237.5 74.5781,237.3125 74.5781,236.8906 L74.5781,235.4688 C74.5781,235.0313 74.5625,234.9063 74.4688,234.75 C74.3125,234.4844 74.0313,234.3438 73.7344,234.3438 C73.4375,234.3438 73.2344,234.4375 73.0156,234.75 L72.8438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="117" x="84.5" y="243.8467">ActivityWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="56.5" x2="203.5" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="56.5" x2="203.5" y1="263" y2="263"/></g><!--class FragmentAndViewModelWatcher--><g id="elem_FragmentAndViewModelWatcher"><rect fill="#F1F1F1" height="48" id="FragmentAndViewModelWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="268" x="421" y="223"/><ellipse cx="436" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M438.3438,234.6719 C437.4063,234.2344 436.8125,234.0938 435.9375,234.0938 C433.3125,234.0938 431.3125,236.1719 431.3125,238.8906 L431.3125,240.0156 C431.3125,242.5938 433.4219,244.4844 436.3125,244.4844 C437.5313,244.4844 438.6875,244.1875 439.4375,243.6406 C440.0156,243.2344 440.3438,242.7813 440.3438,242.3906 C440.3438,241.9375 439.9531,241.5469 439.4844,241.5469 C439.2656,241.5469 439.0625,241.625 438.875,241.8125 C438.4219,242.2969 438.4219,242.2969 438.2344,242.3906 C437.8125,242.6563 437.125,242.7813 436.3594,242.7813 C434.3125,242.7813 433.0156,241.6875 433.0156,239.9844 L433.0156,238.8906 C433.0156,237.1094 434.2656,235.7969 436,235.7969 C436.5781,235.7969 437.1875,235.9531 437.6563,236.2031 C438.1406,236.4844 438.3125,236.7031 438.4063,237.1094 C438.4688,237.5156 438.5,237.6406 438.6406,237.7656 C438.7813,237.9063 439.0156,238.0156 439.2344,238.0156 C439.5,238.0156 439.7656,237.875 439.9375,237.6563 C440.0469,237.5 440.0781,237.3125 440.0781,236.8906 L440.0781,235.4688 C440.0781,235.0313 440.0625,234.9063 439.9688,234.75 C439.8125,234.4844 439.5313,234.3438 439.2344,234.3438 C438.9375,234.3438 438.7344,234.4375 438.5156,234.75 L438.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="236" x="450" y="243.8467">FragmentAndViewModelWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="422" x2="688" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="422" x2="688" y1="263" y2="263"/></g><!--class RootViewWatcher--><g id="elem_RootViewWatcher"><rect fill="#F1F1F1" height="48" id="RootViewWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="162" x="724" y="223"/><ellipse cx="739" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M741.3438,234.6719 C740.4063,234.2344 739.8125,234.0938 738.9375,234.0938 C736.3125,234.0938 734.3125,236.1719 734.3125,238.8906 L734.3125,240.0156 C734.3125,242.5938 736.4219,244.4844 739.3125,244.4844 C740.5313,244.4844 741.6875,244.1875 742.4375,243.6406 C743.0156,243.2344 743.3438,242.7813 743.3438,242.3906 C743.3438,241.9375 742.9531,241.5469 742.4844,241.5469 C742.2656,241.5469 742.0625,241.625 741.875,241.8125 C741.4219,242.2969 741.4219,242.2969 741.2344,242.3906 C740.8125,242.6563 740.125,242.7813 739.3594,242.7813 C737.3125,242.7813 736.0156,241.6875 736.0156,239.9844 L736.0156,238.8906 C736.0156,237.1094 737.2656,235.7969 739,235.7969 C739.5781,235.7969 740.1875,235.9531 740.6563,236.2031 C741.1406,236.4844 741.3125,236.7031 741.4063,237.1094 C741.4688,237.5156 741.5,237.6406 741.6406,237.7656 C741.7813,237.9063 742.0156,238.0156 742.2344,238.0156 C742.5,238.0156 742.7656,237.875 742.9375,237.6563 C743.0469,237.5 743.0781,237.3125 743.0781,236.8906 L743.0781,235.4688 C743.0781,235.0313 743.0625,234.9063 742.9688,234.75 C742.8125,234.4844 742.5313,234.3438 742.2344,234.3438 C741.9375,234.3438 741.7344,234.4375 741.5156,234.75 L741.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="130" x="753" y="243.8467">RootViewWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="725" x2="885" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="725" x2="885" y1="263" y2="263"/></g><!--class ServiceWatcher--><g id="elem_ServiceWatcher"><rect fill="#F1F1F1" height="48" id="ServiceWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="146" x="240" y="223"/><ellipse cx="255" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M257.3438,234.6719 C256.4063,234.2344 255.8125,234.0938 254.9375,234.0938 C252.3125,234.0938 250.3125,236.1719 250.3125,238.8906 L250.3125,240.0156 C250.3125,242.5938 252.4219,244.4844 255.3125,244.4844 C256.5313,244.4844 257.6875,244.1875 258.4375,243.6406 C259.0156,243.2344 259.3438,242.7813 259.3438,242.3906 C259.3438,241.9375 258.9531,241.5469 258.4844,241.5469 C258.2656,241.5469 258.0625,241.625 257.875,241.8125 C257.4219,242.2969 257.4219,242.2969 257.2344,242.3906 C256.8125,242.6563 256.125,242.7813 255.3594,242.7813 C253.3125,242.7813 252.0156,241.6875 252.0156,239.9844 L252.0156,238.8906 C252.0156,237.1094 253.2656,235.7969 255,235.7969 C255.5781,235.7969 256.1875,235.9531 256.6563,236.2031 C257.1406,236.4844 257.3125,236.7031 257.4063,237.1094 C257.4688,237.5156 257.5,237.6406 257.6406,237.7656 C257.7813,237.9063 258.0156,238.0156 258.2344,238.0156 C258.5,238.0156 258.7656,237.875 258.9375,237.6563 C259.0469,237.5 259.0781,237.3125 259.0781,236.8906 L259.0781,235.4688 C259.0781,235.0313 259.0625,234.9063 258.9688,234.75 C258.8125,234.4844 258.5313,234.3438 258.2344,234.3438 C257.9375,234.3438 257.7344,234.4375 257.5156,234.75 L257.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="114" x="269" y="243.8467">ServiceWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="241" x2="385" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="241" x2="385" y1="263" y2="263"/></g><!--class AppWatcher--><g id="elem_AppWatcher"><rect fill="#F1F1F1" height="48" id="AppWatcher" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="123" x="372.5" y="7"/><ellipse cx="387.5" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M389.8438,18.6719 C388.9063,18.2344 388.3125,18.0938 387.4375,18.0938 C384.8125,18.0938 382.8125,20.1719 382.8125,22.8906 L382.8125,24.0156 C382.8125,26.5938 384.9219,28.4844 387.8125,28.4844 C389.0313,28.4844 390.1875,28.1875 390.9375,27.6406 C391.5156,27.2344 391.8438,26.7813 391.8438,26.3906 C391.8438,25.9375 391.4531,25.5469 390.9844,25.5469 C390.7656,25.5469 390.5625,25.625 390.375,25.8125 C389.9219,26.2969 389.9219,26.2969 389.7344,26.3906 C389.3125,26.6563 388.625,26.7813 387.8594,26.7813 C385.8125,26.7813 384.5156,25.6875 384.5156,23.9844 L384.5156,22.8906 C384.5156,21.1094 385.7656,19.7969 387.5,19.7969 C388.0781,19.7969 388.6875,19.9531 389.1563,20.2031 C389.6406,20.4844 389.8125,20.7031 389.9063,21.1094 C389.9688,21.5156 390,21.6406 390.1406,21.7656 C390.2813,21.9063 390.5156,22.0156 390.7344,22.0156 C391,22.0156 391.2656,21.875 391.4375,21.6563 C391.5469,21.5 391.5781,21.3125 391.5781,20.8906 L391.5781,19.4688 C391.5781,19.0313 391.5625,18.9063 391.4688,18.75 C391.3125,18.4844 391.0313,18.3438 390.7344,18.3438 C390.4375,18.3438 390.2344,18.4375 390.0156,18.75 L389.8438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="91" x="401.5" y="27.8467">AppWatcher</text><line style="stroke:#181818;stroke-width:0.5;" x1="373.5" x2="494.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="373.5" x2="494.5" y1="47" y2="47"/></g><!--reverse link ReachabilityWatcher to ObjectWatcher--><g id="link_ReachabilityWatcher_ObjectWatcher"><path codeline="2" d="M459,397.041 C459,413.814 459,418.95 459,438.688 " fill="none" id="ReachabilityWatcher-backto-ObjectWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="459,379.041,453,397.041,465,397.041,459,379.041" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ObjectWatcher to KeyedWeakReference--><g id="link_ObjectWatcher_KeyedWeakReference"><path codeline="7" d="M519.0868,527.6833 C544.1748,547.3845 564.149,563.0687 585.51,579.8428 " fill="none" id="ObjectWatcher-backto-KeyedWeakReference" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="509.649,520.272,511.8974,527.1236,519.0868,527.6833,516.8383,520.8317,509.649,520.272" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="508.7921" y="539.7718">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="568.9282" y="568.8146">n</text></g><!--reverse link WeakReference to KeyedWeakReference--><g id="link_WeakReference_KeyedWeakReference"><path codeline="8" d="M727.5012,514.6579 C699.6992,536.4899 672.321,557.988 644.476,579.8541 " fill="none" id="WeakReference-backto-KeyedWeakReference" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="741.658,503.541,723.7956,509.9389,731.2068,519.3768,741.658,503.541" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link InstallableWatcher to ActivityWatcher--><g id="link_InstallableWatcher_ActivityWatcher"><path codeline="11" d="M351.0406,168.9266 C300.1366,186.6766 247.034,205.192 196.097,222.953 " fill="none" id="InstallableWatcher-backto-ActivityWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="368.037,163,349.0651,163.2611,353.0162,174.592,368.037,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link InstallableWatcher to FragmentAndViewModelWatcher--><g id="link_InstallableWatcher_FragmentAndViewModelWatcher"><path codeline="12" d="M473.7945,174.8609 C493.9515,192.5189 508.131,204.941 528.378,222.678 " fill="none" id="InstallableWatcher-backto-FragmentAndViewModelWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="460.255,163,469.8409,179.3741,477.7482,170.3478,460.255,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link InstallableWatcher to RootViewWatcher--><g id="link_InstallableWatcher_RootViewWatcher"><path codeline="13" d="M531.8084,167.9451 C593.9314,185.6951 662.173,205.192 724.336,222.953 " fill="none" id="InstallableWatcher-backto-RootViewWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="514.501,163,530.16,173.7143,533.4568,162.176,514.501,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link InstallableWatcher to ServiceWatcher--><g id="link_InstallableWatcher_ServiceWatcher"><path codeline="14" d="M394.2055,174.8609 C374.0485,192.5189 359.869,204.941 339.622,222.678 " fill="none" id="InstallableWatcher-backto-ServiceWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="407.745,163,390.2518,170.3478,398.1591,179.3741,407.745,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ActivityWatcher to ReachabilityWatcher--><g id="link_ActivityWatcher_ReachabilityWatcher"><path codeline="16" d="M212.8098,274.6801 C267.8998,292.4301 332.342,313.192 387.468,330.953 " fill="none" id="ActivityWatcher-backto-ReachabilityWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="201.388,271,205.8722,276.6473,212.8098,274.6801,208.3256,269.0328,201.388,271" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link FragmentAndViewModelWatcher to ReachabilityWatcher--><g id="link_FragmentAndViewModelWatcher_ReachabilityWatcher"><path codeline="17" d="M526.1137,279.8945 C510.1217,297.5525 496.186,312.941 480.121,330.678 " fill="none" id="FragmentAndViewModelWatcher-backto-ReachabilityWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="534.169,271,527.1765,272.7621,526.1137,279.8945,533.1062,278.1323,534.169,271" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link RootViewWatcher to ReachabilityWatcher--><g id="link_RootViewWatcher_ReachabilityWatcher"><path codeline="18" d="M718.4494,274.5152 C660.5134,292.2652 592.203,313.192 534.228,330.953 " fill="none" id="RootViewWatcher-backto-ReachabilityWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="729.923,271,723.0145,268.9331,718.4494,274.5152,725.3579,276.5821,729.923,271" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ServiceWatcher to ReachabilityWatcher--><g id="link_ServiceWatcher_ReachabilityWatcher"><path codeline="19" d="M354.3905,278.0502 C378.7955,295.7692 402.678,313.108 427.13,330.862 " fill="none" id="ServiceWatcher-backto-ReachabilityWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="344.68,271,347.1852,277.762,354.3905,278.0502,351.8853,271.2883,344.68,271" style="stroke:#181818;stroke-width:1.0;"/></g><!--link ActivityWatcher to ActivityLifecycleCallbacks--><g id="link_ActivityWatcher_ActivityLifecycleCallbacks"><path codeline="22" d="M130,271 C130,288.658 130,306.941 130,324.678 " fill="none" id="ActivityWatcher-to-ActivityLifecycleCallbacks" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="130,330.678,134,321.678,130,325.678,126,321.678,130,330.678" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AppWatcher to InstallableWatcher--><g id="link_AppWatcher_InstallableWatcher"><path codeline="24" d="M434,67 C434,84.658 434,96.941 434,114.678 " fill="none" id="AppWatcher-backto-InstallableWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="434,55,430,61,434,67,438,61,434,55" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="424.975" y="75.1558">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="425.025" y="104.0045">n</text></g><!--link AppWatcher to ActivityWatcher--><g id="link_AppWatcher_ActivityWatcher"><path codeline="25" d="M398.742,55.07 C373.789,71.525 339.631,94.313 310,115 C257.077,151.949 201.4206,192.8625 165.7676,219.3305 " fill="none" id="AppWatcher-to-ActivityWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="160.95,222.907,170.5607,220.754,164.9646,219.9266,165.792,214.3306,160.95,222.907" style="stroke:#181818;stroke-width:1.0;"/></g><!--link AppWatcher to FragmentAndViewModelWatcher--><g id="link_AppWatcher_FragmentAndViewModelWatcher"><path codeline="26" d="M473.769,55.028 C495.078,69.491 519.8,90.112 534,115 C553.291,148.81 556.3093,189.0712 556.1013,216.6092 " fill="none" id="AppWatcher-to-FragmentAndViewModelWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="556.056,222.609,560.1239,213.6395,556.0938,217.6091,552.1241,213.579,556.056,222.609" style="stroke:#181818;stroke-width:1.0;"/></g><!--link AppWatcher to RootViewWatcher--><g id="link_AppWatcher_RootViewWatcher"><path codeline="27" d="M474.056,55.105 C545.443,96.283 688.6477,178.886 759.9137,219.994 " fill="none" id="AppWatcher-to-RootViewWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="765.111,222.992,759.3136,215.0302,760.7799,220.4937,755.3164,221.96,765.111,222.992" style="stroke:#181818;stroke-width:1.0;"/></g><!--link AppWatcher to ServiceWatcher--><g id="link_AppWatcher_ServiceWatcher"><path codeline="28" d="M394.231,55.028 C372.922,69.491 348.2,90.112 334,115 C314.709,148.81 311.6907,189.0712 311.8987,216.6092 " fill="none" id="AppWatcher-to-ServiceWatcher" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="311.944,222.609,315.8759,213.579,311.9062,217.6091,307.8761,213.6395,311.944,222.609" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[ZPBHQuCm4CRVyrS47ySSx7M888F1sCgOXVNvFCysQnPTJ5jas_y-goWcZMrzoztlak- -Jw4CwGAGU4g06yY45APPWS4DQUQfyUWt3FbRzabe1WmbrBLTup-Cjz-XE-Lzg-OFV05Lj3HQgFKjVw66yXN1DgM2D2cak1lwtj6EMdOilnyBKQAQcFqn-vdWFk0thQ101Pxxc7NgfNie9aONdbLjG4h890tRdPRwYn8qOZynQuvxqh3-8cKIbNy8EYpAdEIbcRGipH6-n2r9xmMEKfcZgRF65-mPJRCpZgPPpjOqYqrCJwfA2WGZIdKtRF0g2i869JssUsU0s_fakJ2ChnrbBUVxPJnnJyZk0ITbftqkN0TrCtNQjct_]--></g></svg>

<h2 id="初始化"><a href="#初始化" class="headerlink" title="初始化"></a>初始化</h2><p>引入LeakCanary时，只需要引入maven库的坐标即可，如下：</p>
<figure class="highlight gradle"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">dependencies</span> &#123;</span><br><span class="line">  <span class="comment">// debugImplementation because LeakCanary should only run in debug builds.</span></span><br><span class="line">  debugImplementation <span class="string">&#x27;com.squareup.leakcanary:leakcanary-android:2.12&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>而不需要进行任何的代码改动就可以使用LeakCanary了。另外，引入leakcanary时使用的是debugImplementation表示只在debug版本中才会集成leakcanary，release版本不会集成。</p>
<p>那么，leakcanary如何完成初始化呢？</p>
<p>leakcanary使用了<code>ContentProvider</code>来进行初始化，当app启动时系统会自动初始化注册的ContentProvider。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">application</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">provider</span></span></span><br><span class="line"><span class="tag">      <span class="attr">android:name</span>=<span class="string">&quot;leakcanary.internal.MainProcessAppWatcherInstaller&quot;</span></span></span><br><span class="line"><span class="tag">      <span class="attr">android:authorities</span>=<span class="string">&quot;$&#123;applicationId&#125;.leakcanary-installer&quot;</span></span></span><br><span class="line"><span class="tag">      <span class="attr">android:enabled</span>=<span class="string">&quot;@bool/leak_canary_watcher_auto_install&quot;</span></span></span><br><span class="line"><span class="tag">      <span class="attr">android:exported</span>=<span class="string">&quot;false&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">application</span>&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">internal</span> <span class="keyword">class</span> <span class="title class_">MainProcessAppWatcherInstaller</span> : <span class="type">ContentProvider</span>() &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">override</span> <span class="function"><span class="keyword">fun</span> <span class="title">onCreate</span><span class="params">()</span></span>: <span class="built_in">Boolean</span> &#123;</span><br><span class="line">    <span class="keyword">val</span> application = context!!.applicationContext <span class="keyword">as</span> Application</span><br><span class="line">    AppWatcher.manualInstall(application)</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">  &#125;</span><br><span class="line">  ......</span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/faedbb97.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/48a4fa29.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/48a4fa29.html" class="post-title-link" itemprop="url">Handler源码解析</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-05 08:38:01" itemprop="dateCreated datePublished" datetime="2023-09-05T08:38:01+08:00">2023-09-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-12-15 11:54:37" itemprop="dateModified" datetime="2023-12-15T11:54:37+08:00">2023-12-15</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">Android消息循环</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="当前线程启动消息队列"><a href="#当前线程启动消息队列" class="headerlink" title="当前线程启动消息队列"></a>当前线程启动消息队列</h2><p>Thread默认是没有消息循环机制的，而Looper就是在Thread基础上运行一个消息循环，通过<code>Looper.prepare()</code>可以把当前线程初始化为一个<strong>Looper thread</strong>。一个典型的Looper thread创建示例如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">LooperThread</span> <span class="keyword">extends</span> <span class="title class_">Thread</span> &#123;</span><br><span class="line">    <span class="keyword">public</span> Handler mHandler;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">        Looper.prepare();</span><br><span class="line">        mHandler = <span class="keyword">new</span> <span class="title class_">Handler</span>(Looper.myLooper()) &#123;</span><br><span class="line">            <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">handleMessage</span><span class="params">(Message msg)</span> &#123;</span><br><span class="line">                <span class="comment">//在此处理消息</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        Looper.loop();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上述代码分为三部：1）调用Looper.prepare()初始化Looper；2）创建一个Handler用于与Looper进行交互；3）调用Looper.loop()启动消息循环。下面分别看下这三步是如何实现的：</p>
<h3 id="初始化Looper-prepare"><a href="#初始化Looper-prepare" class="headerlink" title="初始化Looper.prepare()"></a>初始化Looper.prepare()</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//android-12.1.0_r27\frameworks\base\core\java\android\os\Looper.java</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">final</span> ThreadLocal&lt;Looper&gt; sThreadLocal = <span class="keyword">new</span> <span class="title class_">ThreadLocal</span>&lt;Looper&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">prepare</span><span class="params">()</span> &#123; <span class="comment">//prepare是静态方法</span></span><br><span class="line">        prepare(<span class="literal">true</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">prepare</span><span class="params">(<span class="type">boolean</span> quitAllowed)</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (sThreadLocal.get() != <span class="literal">null</span>) &#123;</span><br><span class="line">            <span class="comment">//一个线程中Looper.prepare()只能执行一次，否则会抛出异常</span></span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">RuntimeException</span>(<span class="string">&quot;Only one Looper may be created per thread&quot;</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//构造了一个Looper放到ThreadLocal中</span></span><br><span class="line">        sThreadLocal.set(<span class="keyword">new</span> <span class="title class_">Looper</span>(quitAllowed));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//Looper的构造方法也很简单：1）创建消息队列；2）获取当先线程句柄；</span></span><br><span class="line">    <span class="keyword">private</span> <span class="title function_">Looper</span><span class="params">(<span class="type">boolean</span> quitAllowed)</span> &#123;</span><br><span class="line">        mQueue = <span class="keyword">new</span> <span class="title class_">MessageQueue</span>(quitAllowed);</span><br><span class="line">        mThread = Thread.currentThread();</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h3 id="创建Handler"><a href="#创建Handler" class="headerlink" title="创建Handler"></a>创建Handler</h3><p>用户无法直接使用Looper来进行消息发送和处理，而是需要通过一个Handler来实现。使用Handler可以发送和处理Message，或者运行一个Runnable。每个Handler都会绑定一个Looper，Handler将会把message和runnable投递到Looper的消息队列中，然后Looper thread将会执行这些message和runnable。</p>
<p>下图是Handler与Looper、Thread、MessageQueue之间的对应关系，Thread和Looper是一对一的关系，否则会抛出异常，一个Looper只有一个消息队列，但是可以多个Handler对应同一个Looper。</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="243px" preserveAspectRatio="none" style="width:388px;height:243px;background:#FFFFFF;" version="1.1" viewBox="0 0 388 243" width="388px" zoomAndPan="magnify"><defs/><g><!--entity Looper--><g id="elem_Looper"><rect fill="#F1F1F1" height="36.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="71" x="220" y="104"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="51" x="230" y="126.9951">Looper</text></g><!--entity Thread--><g id="elem_Thread"><rect fill="#F1F1F1" height="36.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="70" x="221.5" y="201"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="50" x="231.5" y="223.9951">Thread</text></g><!--entity MessageQueue--><g id="elem_MessageQueue"><rect fill="#F1F1F1" height="36.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="126" x="60.5" y="201"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="106" x="70.5" y="223.9951">MessageQueue</text></g><!--entity Handler1--><g id="elem_Handler1"><rect fill="#F1F1F1" height="36.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="84" x="137.5" y="7"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="64" x="147.5" y="29.9951">Handler1</text></g><!--entity Handler2--><g id="elem_Handler2"><rect fill="#F1F1F1" height="36.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="83" x="7" y="7"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="63" x="17" y="29.9951">Handler2</text></g><!--entity Handler3--><g id="elem_Handler3"><rect fill="#F1F1F1" height="36.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="84" x="269.5" y="7"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="64" x="279.5" y="29.9951">Handler3</text></g><!--reverse link Looper to Thread--><g id="link_Looper_Thread"><path d="M255.8097,152.4238 C255.9907,169.5648 256.138,183.5832 256.318,200.686 " fill="none" id="Looper-backto-Thread" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="255.683,140.4245,251.7466,146.4664,255.8097,152.4238,259.7461,146.3819,255.683,140.4245" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Looper to MessageQueue--><g id="link_Looper_MessageQueue"><path d="M221.8562,147.2135 C197.9332,164.4307 171.086,183.7524 147.226,200.9242 " fill="none" id="Looper-backto-MessageQueue" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="231.596,140.2038,224.3895,140.462,221.8562,147.2135,229.0626,146.9553,231.596,140.2038" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Handler1 to Looper--><g id="link_Handler1_Looper"><path d="M200.9358,52.7949 C214.6478,69.9369 227.967,86.583 241.649,103.686 " fill="none" id="Handler1-backto-Looper" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="193.44,43.424,194.0643,50.608,200.9358,52.7949,200.3115,45.6108,193.44,43.424" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Handler2 to Looper--><g id="link_Handler2_Looper"><path d="M96.8924,48.2092 C134.8743,65.6402 182.305,87.408 219.678,104.56 " fill="none" id="Handler2-backto-Looper" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="85.9861,43.204,89.7708,49.3421,96.8924,48.2092,93.1077,42.0712,85.9861,43.204" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Handler3 to Looper--><g id="link_Handler3_Looper"><path d="M295.1356,53.7618 C285.0316,70.9038 275.788,86.583 265.706,103.686 " fill="none" id="Handler3-backto-Looper" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="301.229,43.424,294.7364,46.5618,295.1356,53.7618,301.6282,50.624,301.229,43.424" style="stroke:#181818;stroke-width:1.0;"/></g><!--link Handler1 to MessageQueue--><g id="link_Handler1_MessageQueue"><path d="M169.356,43.044 C160.642,58.449 148.42,82.017 141.5,104 C131.032,137.2554 126.9642,171.9891 125.1212,194.6595 " fill="none" id="Handler1-to-MessageQueue" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:1.0,3.0;"/><polygon fill="#181818" points="124.635,200.6398,129.3511,191.9935,125.0401,195.6562,121.3774,191.3453,124.635,200.6398" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="59" x="142.5" y="126.5669">message</text></g><!--link Handler2 to MessageQueue--><g id="link_Handler2_MessageQueue"><path d="M48.264,43.315 C48.5367,66.287 51.0893,107.698 64.5,140 C74.2007,163.3655 88.5232,181.5495 102.2059,196.3513 " fill="none" id="Handler2-to-MessageQueue" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:1.0,3.0;"/><polygon fill="#181818" points="106.2787,200.7572,103.1068,191.4331,102.8847,197.0856,97.2322,196.8635,106.2787,200.7572" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="59" x="65.5" y="126.5669">message</text></g><!--link Handler3 to MessageQueue--><g id="link_Handler3_MessageQueue"><path d="M316.368,43.194 C322.059,67.15 328.371,110.895 308.5,140 C293.465,162.0218 236.0385,183.7624 187.6605,199.1559 " fill="none" id="Handler3-to-MessageQueue" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:1.0,3.0;"/><polygon fill="#181818" points="181.943,200.9752,191.7322,202.058,186.7076,199.4591,189.3065,194.4346,181.943,200.9752" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="59" x="321.5" y="126.5669">message</text></g><!--SRC=[AyxEp2j8B4hCLKZEpot8pqlDAmakgSn9LIXAJIv9p4lFIUMAzidFBqWjYbNGqjLLY0x9A4fDJ8b54_LDBIvEJ4yDB4qjJGNAUIJcfUIa5Xb2PQ5AuU96ECIDSOW3pT6DJialAKbDYTMrGxDDmKeX5y97DfyazSR4gGS0]--></g></svg>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/48a4fa29.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/c7038aa0.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/c7038aa0.html" class="post-title-link" itemprop="url">Java 公平锁和非公平锁</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-02 11:59:43" itemprop="dateCreated datePublished" datetime="2023-09-02T11:59:43+08:00">2023-09-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-09-04 11:22:46" itemprop="dateModified" datetime="2023-09-04T11:22:46+08:00">2023-09-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">本文基于Java的ReentrantLock类从源码角度分析公平锁和非公平锁的实现原理</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>公平锁：指的是多个线程等待同一个锁时，等待时间最长的线程将会优先获取到锁。但是，这也会导致当线程尝试获取锁时，很大概率会进入阻塞状态，有很高的状态切换成本，因此，会降低吞吐量和执行效率。</p>
<p>非公平锁：不会保证一个特定获取到锁的顺序。当线程尝试获取锁时，会优先通过CAS尝试获取锁，如果失败了才会进入等待队列。非公平锁的执行效率更高，因为线程尝试获取锁的时候，如果能够直接获取到锁，可以节省线程的上下文切换带来的时间和性能上的开销。但是，可能会导致有的线程永远也获取不到锁。</p>
<p>Java中的<code>synchronized</code>是非公平锁，<code>ReentrantLock</code>默认也是非公平锁，并且是可重入的。<code>ReentrantLock</code>则可以通过<code>fair</code>来设置为公平锁。下面是<code>ReentrantLock</code>的类图结构：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="386px" preserveAspectRatio="none" style="width:345px;height:386px;background:#FFFFFF;" version="1.1" viewBox="0 0 345 386" width="345px" zoomAndPan="magnify"><defs/><g><!--class AbstractOwnableSynchronizer--><g id="elem_AbstractOwnableSynchronizer"><rect codeline="1" fill="#F1F1F1" height="48" id="AbstractOwnableSynchronizer" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="246" x="92" y="7"/><ellipse cx="107" cy="23" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M109.0781,24.8125 L109.4688,25.7969 L109.0781,25.7969 C108.625,25.7969 108.5156,25.8125 108.3594,25.9219 C108.1094,26.0781 107.9531,26.3594 107.9531,26.6563 C107.9531,26.9219 108.0938,27.1719 108.3125,27.3281 C108.4531,27.4531 108.6563,27.5 109.0781,27.5 L111.4375,27.5 C111.7969,27.5 112.0156,27.4688 112.1563,27.375 C112.4063,27.2344 112.5625,26.9375 112.5625,26.6563 C112.5625,26.375 112.4219,26.125 112.2031,25.9688 C112.0313,25.8281 111.875,25.7969 111.4063,25.7969 L108.0156,17.5938 L104.3438,17.5938 C103.8906,17.5938 103.7656,17.6094 103.6094,17.7031 C103.3594,17.875 103.2031,18.1563 103.2031,18.4375 C103.2031,18.7188 103.3438,18.9688 103.5625,19.1406 C103.7344,19.25 103.9063,19.2813 104.3438,19.2813 L105.4219,19.2813 L102.7813,25.7969 C102.3594,25.7969 102.2031,25.8125 102.0469,25.9219 C101.7969,26.0781 101.6406,26.3594 101.6406,26.6563 C101.6406,27.2188 102.0156,27.5 102.7656,27.5 L105.0313,27.5 C105.3906,27.5 105.6094,27.4688 105.7344,27.375 C106,27.2344 106.1406,26.9375 106.1406,26.6563 C106.1406,26.375 106.0156,26.125 105.7969,25.9531 C105.625,25.8281 105.4844,25.7969 105.0313,25.7969 L104.6406,25.7969 L105.0313,24.8125 L109.0781,24.8125 Z M108.375,23.1094 L105.7031,23.1094 L107.0469,19.8438 L108.375,23.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="214" x="121" y="27.8467">AbstractOwnableSynchronizer</text><line style="stroke:#181818;stroke-width:0.5;" x1="93" x2="337" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="93" x2="337" y1="47" y2="47"/></g><!--class AbstractQueuedSynchronizer--><g id="elem_AbstractQueuedSynchronizer"><rect codeline="2" fill="#F1F1F1" height="48" id="AbstractQueuedSynchronizer" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="240" x="95" y="115"/><ellipse cx="110" cy="131" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M112.0781,132.8125 L112.4688,133.7969 L112.0781,133.7969 C111.625,133.7969 111.5156,133.8125 111.3594,133.9219 C111.1094,134.0781 110.9531,134.3594 110.9531,134.6563 C110.9531,134.9219 111.0938,135.1719 111.3125,135.3281 C111.4531,135.4531 111.6563,135.5 112.0781,135.5 L114.4375,135.5 C114.7969,135.5 115.0156,135.4688 115.1563,135.375 C115.4063,135.2344 115.5625,134.9375 115.5625,134.6563 C115.5625,134.375 115.4219,134.125 115.2031,133.9688 C115.0313,133.8281 114.875,133.7969 114.4063,133.7969 L111.0156,125.5938 L107.3438,125.5938 C106.8906,125.5938 106.7656,125.6094 106.6094,125.7031 C106.3594,125.875 106.2031,126.1563 106.2031,126.4375 C106.2031,126.7188 106.3438,126.9688 106.5625,127.1406 C106.7344,127.25 106.9063,127.2813 107.3438,127.2813 L108.4219,127.2813 L105.7813,133.7969 C105.3594,133.7969 105.2031,133.8125 105.0469,133.9219 C104.7969,134.0781 104.6406,134.3594 104.6406,134.6563 C104.6406,135.2188 105.0156,135.5 105.7656,135.5 L108.0313,135.5 C108.3906,135.5 108.6094,135.4688 108.7344,135.375 C109,135.2344 109.1406,134.9375 109.1406,134.6563 C109.1406,134.375 109.0156,134.125 108.7969,133.9531 C108.625,133.8281 108.4844,133.7969 108.0313,133.7969 L107.6406,133.7969 L108.0313,132.8125 L112.0781,132.8125 Z M111.375,131.1094 L108.7031,131.1094 L110.0469,127.8438 L111.375,131.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="208" x="124" y="135.8467">AbstractQueuedSynchronizer</text><line style="stroke:#181818;stroke-width:0.5;" x1="96" x2="334" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="96" x2="334" y1="155" y2="155"/></g><!--class Sync--><g id="elem_Sync"><rect codeline="3" fill="#F1F1F1" height="48" id="Sync" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="66" x="182" y="223"/><ellipse cx="197" cy="239" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M199.0781,240.8125 L199.4688,241.7969 L199.0781,241.7969 C198.625,241.7969 198.5156,241.8125 198.3594,241.9219 C198.1094,242.0781 197.9531,242.3594 197.9531,242.6563 C197.9531,242.9219 198.0938,243.1719 198.3125,243.3281 C198.4531,243.4531 198.6563,243.5 199.0781,243.5 L201.4375,243.5 C201.7969,243.5 202.0156,243.4688 202.1563,243.375 C202.4063,243.2344 202.5625,242.9375 202.5625,242.6563 C202.5625,242.375 202.4219,242.125 202.2031,241.9688 C202.0313,241.8281 201.875,241.7969 201.4063,241.7969 L198.0156,233.5938 L194.3438,233.5938 C193.8906,233.5938 193.7656,233.6094 193.6094,233.7031 C193.3594,233.875 193.2031,234.1563 193.2031,234.4375 C193.2031,234.7188 193.3438,234.9688 193.5625,235.1406 C193.7344,235.25 193.9063,235.2813 194.3438,235.2813 L195.4219,235.2813 L192.7813,241.7969 C192.3594,241.7969 192.2031,241.8125 192.0469,241.9219 C191.7969,242.0781 191.6406,242.3594 191.6406,242.6563 C191.6406,243.2188 192.0156,243.5 192.7656,243.5 L195.0313,243.5 C195.3906,243.5 195.6094,243.4688 195.7344,243.375 C196,243.2344 196.1406,242.9375 196.1406,242.6563 C196.1406,242.375 196.0156,242.125 195.7969,241.9531 C195.625,241.8281 195.4844,241.7969 195.0313,241.7969 L194.6406,241.7969 L195.0313,240.8125 L199.0781,240.8125 Z M198.375,239.1094 L195.7031,239.1094 L197.0469,235.8438 L198.375,239.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="34" x="211" y="243.8467">Sync</text><line style="stroke:#181818;stroke-width:0.5;" x1="183" x2="247" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="183" x2="247" y1="263" y2="263"/></g><!--class ReentrantLock--><g id="elem_ReentrantLock"><rect codeline="4" fill="#ADD8E6" height="48" id="ReentrantLock" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="140" x="7" y="223"/><ellipse cx="22" cy="239" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,234.6719 C23.4063,234.2344 22.8125,234.0938 21.9375,234.0938 C19.3125,234.0938 17.3125,236.1719 17.3125,238.8906 L17.3125,240.0156 C17.3125,242.5938 19.4219,244.4844 22.3125,244.4844 C23.5313,244.4844 24.6875,244.1875 25.4375,243.6406 C26.0156,243.2344 26.3438,242.7813 26.3438,242.3906 C26.3438,241.9375 25.9531,241.5469 25.4844,241.5469 C25.2656,241.5469 25.0625,241.625 24.875,241.8125 C24.4219,242.2969 24.4219,242.2969 24.2344,242.3906 C23.8125,242.6563 23.125,242.7813 22.3594,242.7813 C20.3125,242.7813 19.0156,241.6875 19.0156,239.9844 L19.0156,238.8906 C19.0156,237.1094 20.2656,235.7969 22,235.7969 C22.5781,235.7969 23.1875,235.9531 23.6563,236.2031 C24.1406,236.4844 24.3125,236.7031 24.4063,237.1094 C24.4688,237.5156 24.5,237.6406 24.6406,237.7656 C24.7813,237.9063 25.0156,238.0156 25.2344,238.0156 C25.5,238.0156 25.7656,237.875 25.9375,237.6563 C26.0469,237.5 26.0781,237.3125 26.0781,236.8906 L26.0781,235.4688 C26.0781,235.0313 26.0625,234.9063 25.9688,234.75 C25.8125,234.4844 25.5313,234.3438 25.2344,234.3438 C24.9375,234.3438 24.7344,234.4375 24.5156,234.75 L24.3438,234.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="108" x="36" y="243.8467">ReentrantLock</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="146" y1="255" y2="255"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="146" y1="263" y2="263"/></g><!--class NonfairSync--><g id="elem_NonfairSync"><rect fill="#F1F1F1" height="48" id="NonfairSync" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="118" x="86" y="331"/><ellipse cx="101" cy="347" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M103.3438,342.6719 C102.4063,342.2344 101.8125,342.0938 100.9375,342.0938 C98.3125,342.0938 96.3125,344.1719 96.3125,346.8906 L96.3125,348.0156 C96.3125,350.5938 98.4219,352.4844 101.3125,352.4844 C102.5313,352.4844 103.6875,352.1875 104.4375,351.6406 C105.0156,351.2344 105.3438,350.7813 105.3438,350.3906 C105.3438,349.9375 104.9531,349.5469 104.4844,349.5469 C104.2656,349.5469 104.0625,349.625 103.875,349.8125 C103.4219,350.2969 103.4219,350.2969 103.2344,350.3906 C102.8125,350.6563 102.125,350.7813 101.3594,350.7813 C99.3125,350.7813 98.0156,349.6875 98.0156,347.9844 L98.0156,346.8906 C98.0156,345.1094 99.2656,343.7969 101,343.7969 C101.5781,343.7969 102.1875,343.9531 102.6563,344.2031 C103.1406,344.4844 103.3125,344.7031 103.4063,345.1094 C103.4688,345.5156 103.5,345.6406 103.6406,345.7656 C103.7813,345.9063 104.0156,346.0156 104.2344,346.0156 C104.5,346.0156 104.7656,345.875 104.9375,345.6563 C105.0469,345.5 105.0781,345.3125 105.0781,344.8906 L105.0781,343.4688 C105.0781,343.0313 105.0625,342.9063 104.9688,342.75 C104.8125,342.4844 104.5313,342.3438 104.2344,342.3438 C103.9375,342.3438 103.7344,342.4375 103.5156,342.75 L103.3438,342.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="86" x="115" y="351.8467">NonfairSync</text><line style="stroke:#181818;stroke-width:0.5;" x1="87" x2="203" y1="363" y2="363"/><line style="stroke:#181818;stroke-width:0.5;" x1="87" x2="203" y1="371" y2="371"/></g><!--class FairSync--><g id="elem_FairSync"><rect fill="#F1F1F1" height="48" id="FairSync" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="92" x="239" y="331"/><ellipse cx="254" cy="347" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M256.3438,342.6719 C255.4063,342.2344 254.8125,342.0938 253.9375,342.0938 C251.3125,342.0938 249.3125,344.1719 249.3125,346.8906 L249.3125,348.0156 C249.3125,350.5938 251.4219,352.4844 254.3125,352.4844 C255.5313,352.4844 256.6875,352.1875 257.4375,351.6406 C258.0156,351.2344 258.3438,350.7813 258.3438,350.3906 C258.3438,349.9375 257.9531,349.5469 257.4844,349.5469 C257.2656,349.5469 257.0625,349.625 256.875,349.8125 C256.4219,350.2969 256.4219,350.2969 256.2344,350.3906 C255.8125,350.6563 255.125,350.7813 254.3594,350.7813 C252.3125,350.7813 251.0156,349.6875 251.0156,347.9844 L251.0156,346.8906 C251.0156,345.1094 252.2656,343.7969 254,343.7969 C254.5781,343.7969 255.1875,343.9531 255.6563,344.2031 C256.1406,344.4844 256.3125,344.7031 256.4063,345.1094 C256.4688,345.5156 256.5,345.6406 256.6406,345.7656 C256.7813,345.9063 257.0156,346.0156 257.2344,346.0156 C257.5,346.0156 257.7656,345.875 257.9375,345.6563 C258.0469,345.5 258.0781,345.3125 258.0781,344.8906 L258.0781,343.4688 C258.0781,343.0313 258.0625,342.9063 257.9688,342.75 C257.8125,342.4844 257.5313,342.3438 257.2344,342.3438 C256.9375,342.3438 256.7344,342.4375 256.5156,342.75 L256.3438,342.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="60" x="268" y="351.8467">FairSync</text><line style="stroke:#181818;stroke-width:0.5;" x1="240" x2="330" y1="363" y2="363"/><line style="stroke:#181818;stroke-width:0.5;" x1="240" x2="330" y1="371" y2="371"/></g><!--reverse link ReentrantLock to Sync--><g id="link_ReentrantLock_Sync"><path codeline="5" d="M159.078,247 C170.664,247 170.249,247 181.835,247 " fill="none" id="ReentrantLock-backto-Sync" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="147.078,247,153.078,251,159.078,247,153.078,243,147.078,247" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AbstractOwnableSynchronizer to AbstractQueuedSynchronizer--><g id="link_AbstractOwnableSynchronizer_AbstractQueuedSynchronizer"><path codeline="6" d="M215,73 C215,90.658 215,96.941 215,114.678 " fill="none" id="AbstractOwnableSynchronizer-backto-AbstractQueuedSynchronizer" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="215,55,209,73,221,73,215,55" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AbstractQueuedSynchronizer to Sync--><g id="link_AbstractQueuedSynchronizer_Sync"><path codeline="7" d="M215,181 C215,198.658 215,204.941 215,222.678 " fill="none" id="AbstractQueuedSynchronizer-backto-Sync" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="215,163,209,181,221,181,215,163" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Sync to NonfairSync--><g id="link_Sync_NonfairSync"><path codeline="8" d="M189.892,286.0204 C178.231,303.6788 172.115,312.9408 160.401,330.6784 " fill="none" id="Sync-backto-NonfairSync" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="199.811,271,184.8852,282.7141,194.8988,289.3268,199.811,271" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Sync to FairSync--><g id="link_Sync_FairSync"><path codeline="9" d="M240.108,286.0204 C251.769,303.6788 257.885,312.9408 269.599,330.6784 " fill="none" id="Sync-backto-FairSync" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="230.189,271,235.1012,289.3268,245.1148,282.7141,230.189,271" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[IqmgBYbAJ2vHS8Go_Clp4fDoKeChyv8pYlBpCgjIYxWIqHK5bgQMfgPWLmCIvKhEIImkLWXAJSq32kQL-EGdPoievsIcPvGavPIcSg5AQEb2DE4sNK6tj42tnWwl8q4ST7LOt0bMPbEZgwlWbv-NbfXP1BOQ8Ue65G80]--></g></svg>

<h2 id="公平锁加锁"><a href="#公平锁加锁" class="headerlink" title="公平锁加锁"></a>公平锁加锁</h2><p>公平锁加锁过程的方法调用：<code>ReentrantLock#lock()</code> &rarr; <code>ReentrantLock.FairSync#lock()</code> &rarr; <code>AbstractQueuedSynchronizer#acquire(1)</code>。下面看下acquire的代码实现：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 【AbstractQueuedSynchronizer.java】</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title function_">acquire</span><span class="params">(<span class="type">int</span> arg)</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (!tryAcquire(arg) &amp;&amp;</span><br><span class="line">            acquireQueued(addWaiter(Node.EXCLUSIVE), arg))</span><br><span class="line">            selfInterrupt();</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">// 【ReentrantLock.java】</span></span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">final</span> <span class="keyword">class</span> <span class="title class_">FairSync</span> <span class="keyword">extends</span> <span class="title class_">Sync</span> &#123;</span><br><span class="line">        ......</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * Fair version of tryAcquire.  Don&#x27;t grant access unless</span></span><br><span class="line"><span class="comment">         * recursive call or no waiters or is first.</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        <span class="comment">// 只有锁未被锁定、锁重入或者等待队列中没有前辈的情况才会获取成功</span></span><br><span class="line">        <span class="keyword">protected</span> <span class="keyword">final</span> <span class="type">boolean</span> <span class="title function_">tryAcquire</span><span class="params">(<span class="type">int</span> acquires)</span> &#123;</span><br><span class="line">            <span class="keyword">final</span> <span class="type">Thread</span> <span class="variable">current</span> <span class="operator">=</span> Thread.currentThread();</span><br><span class="line">            <span class="type">int</span> <span class="variable">c</span> <span class="operator">=</span> getState();</span><br><span class="line">            <span class="keyword">if</span> (c == <span class="number">0</span>) &#123; <span class="comment">//state为0表示当前是未被锁定状态</span></span><br><span class="line">                <span class="keyword">if</span> (!hasQueuedPredecessors() &amp;&amp; <span class="comment">//判断等待队列是否有排在自己前面的线程</span></span><br><span class="line">                    compareAndSetState(<span class="number">0</span>, acquires)) &#123; <span class="comment">//通过CAS设置锁定状态</span></span><br><span class="line">                    setExclusiveOwnerThread(current); <span class="comment">//独占线程设置为自己</span></span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">true</span>; <span class="comment">//加锁成功</span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span> (current == getExclusiveOwnerThread()) &#123;</span><br><span class="line">                <span class="comment">// 锁的重入，状态加1</span></span><br><span class="line">                <span class="type">int</span> <span class="variable">nextc</span> <span class="operator">=</span> c + acquires;</span><br><span class="line">                <span class="keyword">if</span> (nextc &lt; <span class="number">0</span>)</span><br><span class="line">                    <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">Error</span>(<span class="string">&quot;Maximum lock count exceeded&quot;</span>);</span><br><span class="line">                setState(nextc);</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">true</span>; <span class="comment">//加锁成功</span></span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>; <span class="comment">//加锁失败</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">// 【AbstractQueuedSynchronizer.java】</span></span><br><span class="line"><span class="comment">// addWaiter的作用就是将当前线程添加到等待队列的队尾</span></span><br><span class="line">    <span class="keyword">private</span> Node <span class="title function_">addWaiter</span><span class="params">(Node mode)</span> &#123;</span><br><span class="line">        <span class="type">Node</span> <span class="variable">node</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Node</span>(Thread.currentThread(), mode);</span><br><span class="line">        <span class="comment">// Try the fast path of enq; backup to full enq on failure</span></span><br><span class="line">        <span class="type">Node</span> <span class="variable">pred</span> <span class="operator">=</span> tail;</span><br><span class="line">        <span class="keyword">if</span> (pred != <span class="literal">null</span>) &#123;</span><br><span class="line">            node.prev = pred;</span><br><span class="line">            <span class="keyword">if</span> (compareAndSetTail(pred, node)) &#123;</span><br><span class="line">                pred.next = node;</span><br><span class="line">                <span class="keyword">return</span> node;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        enq(node);</span><br><span class="line">        <span class="keyword">return</span> node;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">boolean</span> <span class="title function_">acquireQueued</span><span class="params">(<span class="keyword">final</span> Node node, <span class="type">int</span> arg)</span> &#123;</span><br><span class="line">        <span class="type">boolean</span> <span class="variable">failed</span> <span class="operator">=</span> <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="type">boolean</span> <span class="variable">interrupted</span> <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line">            <span class="keyword">for</span> (;;) &#123; <span class="comment">//循环</span></span><br><span class="line">                <span class="keyword">final</span> <span class="type">Node</span> <span class="variable">p</span> <span class="operator">=</span> node.predecessor();</span><br><span class="line">                <span class="keyword">if</span> (p == head &amp;&amp; tryAcquire(arg)) &#123;</span><br><span class="line">                    <span class="comment">// 请求锁的当前线程排在了队首，且获取锁成功</span></span><br><span class="line">                    setHead(node); <span class="comment">//设置为head，所以head是持有锁的线程</span></span><br><span class="line">                    p.next = <span class="literal">null</span>; <span class="comment">// help GC</span></span><br><span class="line">                    failed = <span class="literal">false</span>;</span><br><span class="line">                    <span class="keyword">return</span> interrupted;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">if</span> (shouldParkAfterFailedAcquire(p, node) &amp;&amp;</span><br><span class="line">                    parkAndCheckInterrupt()) <span class="comment">//进入blocked状态</span></span><br><span class="line">                    interrupted = <span class="literal">true</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">            <span class="keyword">if</span> (failed)</span><br><span class="line">                cancelAcquire(node);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="1064px" preserveAspectRatio="none" style="width:420px;height:1064px;background:#FFFFFF;" version="1.1" viewBox="0 0 420 1064" width="420px" zoomAndPan="magnify"><defs/><g><ellipse cx="217.5" cy="20" fill="#222222" rx="10" ry="10" style="stroke:#222222;stroke-width:1.0;"/><rect fill="none" height="491.2339" style="stroke:#000000;stroke-width:1.5;" width="398" x="11" y="40"/><path d="M106,40 L106,49.2969 L96,59.2969 L11,59.2969 " fill="none" style="stroke:#000000;stroke-width:1.5;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="85" x="14" y="53.9951">tryAcquire()</text><polygon fill="#F1F1F1" points="42.5,79.2969,161.5,79.2969,173.5,91.2969,161.5,103.2969,42.5,103.2969,30.5,91.2969,42.5,79.2969" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="106" y="113.5073">yes</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="119" x="42.5" y="95.105">&#38145;&#26410;&#34987;&#38145;&#23450; state==0?</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="158" x="23" y="183.4097"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="138" x="33" y="204.5483">CAS&#35774;&#32622;state&#20026;&#38145;&#23450;&#29366;&#24577;</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="152" x="26" y="300.7808"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="132" x="36" y="321.9194">&#24403;&#21069;&#32447;&#31243;&#35774;&#32622;&#20026;&#29420;&#21344;&#32447;&#31243;</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="68" x="68" y="357.2651"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="48" x="78" y="378.4038">&#21152;&#38145;&#25104;&#21151;</text><ellipse cx="102" cy="422.2339" fill="none" rx="11" ry="11" style="stroke:#222222;stroke-width:1.0;"/><ellipse cx="102" cy="422.2339" fill="#222222" rx="6" ry="6" style="stroke:#222222;stroke-width:1.0;"/><polygon fill="#F1F1F1" points="65,252.3784,139,252.3784,151,264.3784,139,276.3784,65,276.3784,53,264.3784,65,252.3784" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="106" y="286.5889">yes</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="74" x="65" y="268.1865">CAS&#35774;&#32622;&#25104;&#21151;?</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="151" y="261.7842">no</text><polygon fill="#F1F1F1" points="52.5,135.0073,151.5,135.0073,163.5,147.0073,151.5,159.0073,52.5,159.0073,40.5,147.0073,52.5,135.0073" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="106" y="169.2178">no</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="99" x="52.5" y="150.8154">&#26377;&#20854;&#20182;&#32447;&#31243;&#27491;&#22312;&#25490;&#38431;</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="163.5" y="144.4131">yes</text><polygon fill="#F1F1F1" points="102,475.2339,114,487.2339,102,499.2339,90,487.2339,102,475.2339" style="stroke:#181818;stroke-width:0.5;"/><polygon fill="#F1F1F1" points="268,79.2969,367,79.2969,379,91.2969,367,103.2969,268,103.2969,256,91.2969,268,79.2969" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="321.5" y="113.5073">yes</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="99" x="268" y="95.105">&#24403;&#21069;&#32447;&#31243;&#24050;&#32463;&#25345;&#26377;&#38145;</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="242" y="88.7026">no</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="69" x="283" y="135.0073"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="49" x="293" y="156.146">state&#21152;1</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="68" x="283.5" y="203.9761"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="48" x="293.5" y="225.1147">&#21152;&#38145;&#25104;&#21151;</text><ellipse cx="317.5" cy="283.9448" fill="none" rx="11" ry="11" style="stroke:#222222;stroke-width:1.0;"/><ellipse cx="317.5" cy="283.9448" fill="#222222" rx="6" ry="6" style="stroke:#222222;stroke-width:1.0;"/><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="128" x="153.5" y="551.2339"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="108" x="163.5" y="572.3726">&#28155;&#21152;&#21040;&#31561;&#24453;&#38431;&#21015;&#38431;&#23614;</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="140" x="147.5" y="697.605"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="120" x="157.5" y="718.7437">&#20877;&#27425;&#35843;&#29992;tryAcquire()</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="134" x="150.5" y="799.9761"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="114" x="160.5" y="821.1147">&#24403;&#21069;&#33410;&#28857;&#35774;&#32622;&#20026;head</text><ellipse cx="217.5" cy="877.4604" fill="none" rx="11" ry="11" style="stroke:#222222;stroke-width:1.0;"/><ellipse cx="217.5" cy="877.4604" fill="#222222" rx="6" ry="6" style="stroke:#222222;stroke-width:1.0;"/><polygon fill="#F1F1F1" points="161,751.5737,274,751.5737,286,763.5737,274,775.5737,161,775.5737,149,763.5737,161,751.5737" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="221.5" y="785.7842">yes</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="113" x="161" y="767.3818">tryAcquire&#21152;&#38145;&#25104;&#21151;&#65311;</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="286" y="760.9795">no</text><polygon fill="#F1F1F1" points="161,649.2026,274,649.2026,286,661.2026,274,673.2026,161,673.2026,149,661.2026,161,649.2026" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="221.5" y="683.4131">yes</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="113" x="161" y="665.0107">node.prev == head</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="286" y="658.6084">no</text><polygon fill="#F1F1F1" points="217.5,930.4604,229.5,942.4604,217.5,954.4604,205.5,942.4604,217.5,930.4604" style="stroke:#181818;stroke-width:0.5;"/><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="116" x="159.5" y="974.4604"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="96" x="169.5" y="995.5991">&#32447;&#31243;&#36827;&#20837;&#38459;&#22622;&#29366;&#24577;</text><polygon fill="#F1F1F1" points="217.5,605.2026,229.5,617.2026,217.5,629.2026,205.5,617.2026,217.5,605.2026" style="stroke:#181818;stroke-width:0.5;"/><polygon fill="#F1F1F1" points="201,1028.4292,234,1028.4292,246,1040.4292,234,1052.4292,201,1052.4292,189,1040.4292,201,1028.4292" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="33" x="201" y="1044.2373">&#27515;&#24490;&#29615;</text><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="334.7495" y2="357.2651"/><polygon fill="#181818" points="98,347.2651,102,357.2651,106,347.2651,102,351.2651" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="391.2339" y2="411.2339"/><polygon fill="#181818" points="98,401.2339,102,411.2339,106,401.2339,102,405.2339" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="276.3784" y2="300.7808"/><polygon fill="#181818" points="98,290.7808,102,300.7808,106,290.7808,102,294.7808" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="151" x2="188" y1="264.3784" y2="264.3784"/><polygon fill="#181818" points="184,355.2651,188,365.2651,192,355.2651,188,359.2651" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="188" x2="188" y1="264.3784" y2="455.2339"/><line style="stroke:#181818;stroke-width:1.0;" x1="188" x2="102" y1="455.2339" y2="455.2339"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="455.2339" y2="475.2339"/><polygon fill="#181818" points="98,465.2339,102,475.2339,106,465.2339,102,469.2339" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="217.3784" y2="252.3784"/><polygon fill="#181818" points="98,242.3784,102,252.3784,106,242.3784,102,246.3784" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="159.0073" y2="183.4097"/><polygon fill="#181818" points="98,173.4097,102,183.4097,106,173.4097,102,177.4097" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="163.5" x2="210" y1="147.0073" y2="147.0073"/><polygon fill="#181818" points="206,327.2651,210,337.2651,214,327.2651,210,331.2651" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="210" x2="210" y1="147.0073" y2="487.2339"/><line style="stroke:#181818;stroke-width:1.0;" x1="210" x2="114" y1="487.2339" y2="487.2339"/><polygon fill="#181818" points="124,483.2339,114,487.2339,124,491.2339,120,487.2339" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="317.5" x2="317.5" y1="168.9761" y2="203.9761"/><polygon fill="#181818" points="313.5,193.9761,317.5,203.9761,321.5,193.9761,317.5,197.9761" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="317.5" x2="317.5" y1="237.9448" y2="272.9448"/><polygon fill="#181818" points="313.5,262.9448,317.5,272.9448,321.5,262.9448,317.5,266.9448" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="103.2969" y2="135.0073"/><polygon fill="#181818" points="98,125.0073,102,135.0073,106,125.0073,102,129.0073" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="499.2339" y2="519.2339"/><polygon fill="#181818" points="98,509.2339,102,519.2339,106,509.2339,102,513.2339" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="317.5" x2="317.5" y1="103.2969" y2="135.0073"/><polygon fill="#181818" points="313.5,125.0073,317.5,135.0073,321.5,125.0073,317.5,129.0073" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="173.5" x2="256" y1="91.2969" y2="91.2969"/><polygon fill="#181818" points="246,87.2969,256,91.2969,246,95.2969,250,91.2969" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="30" y2="64.2969"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="102" y1="64.2969" y2="64.2969"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="102" y1="64.2969" y2="79.2969"/><polygon fill="#181818" points="98,69.2969,102,79.2969,106,69.2969,102,73.2969" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="379" x2="393" y1="91.2969" y2="91.2969"/><line style="stroke:#181818;stroke-width:1.0;" x1="393" x2="393" y1="91.2969" y2="519.2339"/><polygon fill="#181818" points="389,509.2339,393,519.2339,397,509.2339,393,513.2339" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="102" x2="393" y1="519.2339" y2="519.2339"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="519.2339" y2="551.2339"/><polygon fill="#181818" points="213.5,541.2339,217.5,551.2339,221.5,541.2339,217.5,545.2339" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="833.9448" y2="866.4604"/><polygon fill="#181818" points="213.5,856.4604,217.5,866.4604,221.5,856.4604,217.5,860.4604" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="775.5737" y2="799.9761"/><polygon fill="#181818" points="213.5,789.9761,217.5,799.9761,221.5,789.9761,217.5,793.9761" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="286" x2="298" y1="763.5737" y2="763.5737"/><polygon fill="#181818" points="294,832.4604,298,842.4604,302,832.4604,298,836.4604" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="298" x2="298" y1="763.5737" y2="910.4604"/><line style="stroke:#181818;stroke-width:1.0;" x1="298" x2="217.5" y1="910.4604" y2="910.4604"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="910.4604" y2="930.4604"/><polygon fill="#181818" points="213.5,920.4604,217.5,930.4604,221.5,920.4604,217.5,924.4604" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="731.5737" y2="751.5737"/><polygon fill="#181818" points="213.5,741.5737,217.5,751.5737,221.5,741.5737,217.5,745.5737" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="673.2026" y2="697.605"/><polygon fill="#181818" points="213.5,687.605,217.5,697.605,221.5,687.605,217.5,691.605" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="286" x2="316.5" y1="661.2026" y2="661.2026"/><polygon fill="#181818" points="312.5,791.9761,316.5,801.9761,320.5,791.9761,316.5,795.9761" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="316.5" x2="316.5" y1="661.2026" y2="942.4604"/><line style="stroke:#181818;stroke-width:1.0;" x1="316.5" x2="229.5" y1="942.4604" y2="942.4604"/><polygon fill="#181818" points="239.5,938.4604,229.5,942.4604,239.5,946.4604,235.5,942.4604" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="954.4604" y2="974.4604"/><polygon fill="#181818" points="213.5,964.4604,217.5,974.4604,221.5,964.4604,217.5,968.4604" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="629.2026" y2="649.2026"/><polygon fill="#181818" points="213.5,639.2026,217.5,649.2026,221.5,639.2026,217.5,643.2026" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="246" x2="340.5" y1="1040.4292" y2="1040.4292"/><polygon fill="#181818" points="336.5,846.4604,340.5,836.4604,344.5,846.4604,340.5,842.4604" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="340.5" x2="340.5" y1="617.2026" y2="1040.4292"/><line style="stroke:#181818;stroke-width:1.0;" x1="340.5" x2="229.5" y1="617.2026" y2="617.2026"/><polygon fill="#181818" points="239.5,613.2026,229.5,617.2026,239.5,621.2026,235.5,617.2026" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="1008.4292" y2="1028.4292"/><polygon fill="#181818" points="213.5,1018.4292,217.5,1028.4292,221.5,1018.4292,217.5,1022.4292" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="217.5" x2="217.5" y1="585.2026" y2="605.2026"/><polygon fill="#181818" points="213.5,595.2026,217.5,605.2026,221.5,595.2026,217.5,599.2026" style="stroke:#181818;stroke-width:1.0;"/><!--SRC=[bLB1Ji905BptA_RONenUInf3_0I_e955cf22xQhX9XWCBO96YH8b0XeJWe340oYLyZFiBfpy1RlRKX3ZmSlcPJAPcJTlJQGQIDWtKeTfW8nCTE_WK3EWA0bQ78ZpIfRKshF75s_0lJjW8XL1HTdSbW1AG5tCG5CI061KKhDmVZ1rRkXeGbj5qdt2jHOfNyshzO2ifnWN07adkZlhkNJSutBJzv6lJkq1ESb6E8SfXZHIkCHsVSsJA-7nDRPAlgFFzTHeiODB3H-CX4oxmPRXIWlGHAaq7s7IX23C1_MO5XSMQ63dWup3SPPlrHmFtwXpGSwzkYpFvsTKcU_f9TXYph-Yy1Y-llS2VWf19aF78-92dtOjxEQz6d7XbhrzDo8OC0rL53Ilfs9m8st08w0e807Ls7fHCZuhaKvprZ-bbTRgZPTTBz7LT5-VzJzBdzavcli8IsU-_-hLHnUO7DnmSe_pp_EgWviFY-_WxmgE4reIYgJhOBTDow_IDm00]--></g></svg>

<p>有一点需要注意，即使<code>ReentrantLock</code>构造时<code>fair</code>设置为true，使用不带超时的<code>tryLock()</code>加锁时也会使用非公平锁的策略。</p>
<h2 id="非公平锁加锁"><a href="#非公平锁加锁" class="headerlink" title="非公平锁加锁"></a>非公平锁加锁</h2>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/c7038aa0.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/32780962.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/32780962.html" class="post-title-link" itemprop="url">PlantUML样式指南</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2023-09-01 16:03:09 / 修改时间：17:45:25" itemprop="dateCreated datePublished" datetime="2023-09-01T16:03:09+08:00">2023-09-01</time>
    </span>

  
</div>

            <div class="post-description">PlantUML样式指南</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="连接线样式"><a href="#连接线样式" class="headerlink" title="连接线样式"></a>连接线样式</h2><p>连接线的样式支持：bold, plain, dotted，dashed。设置颜色必须可以使用颜色名称，或者16进制的RGB样式，但是必须使用<code>#</code>开头。</p>
<figure class="highlight text"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">A -[dashed,#green]right-&gt; B</span><br><span class="line">A2 -[bold,#ff00ff]-&gt; B2</span><br></pre></td></tr></table></figure>

<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="170px" preserveAspectRatio="none" style="width:150px;height:170px;background:#FFFFFF;" version="1.1" viewBox="0 0 150 170" width="150px" zoomAndPan="magnify"><defs/><g><!--class A1--><g id="elem_A1"><rect codeline="1" fill="#F1F1F1" height="48" id="A1" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="51" x="7" y="115"/><ellipse cx="22" cy="131" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,126.6719 C23.4063,126.2344 22.8125,126.0938 21.9375,126.0938 C19.3125,126.0938 17.3125,128.1719 17.3125,130.8906 L17.3125,132.0156 C17.3125,134.5938 19.4219,136.4844 22.3125,136.4844 C23.5313,136.4844 24.6875,136.1875 25.4375,135.6406 C26.0156,135.2344 26.3438,134.7813 26.3438,134.3906 C26.3438,133.9375 25.9531,133.5469 25.4844,133.5469 C25.2656,133.5469 25.0625,133.625 24.875,133.8125 C24.4219,134.2969 24.4219,134.2969 24.2344,134.3906 C23.8125,134.6563 23.125,134.7813 22.3594,134.7813 C20.3125,134.7813 19.0156,133.6875 19.0156,131.9844 L19.0156,130.8906 C19.0156,129.1094 20.2656,127.7969 22,127.7969 C22.5781,127.7969 23.1875,127.9531 23.6563,128.2031 C24.1406,128.4844 24.3125,128.7031 24.4063,129.1094 C24.4688,129.5156 24.5,129.6406 24.6406,129.7656 C24.7813,129.9063 25.0156,130.0156 25.2344,130.0156 C25.5,130.0156 25.7656,129.875 25.9375,129.6563 C26.0469,129.5 26.0781,129.3125 26.0781,128.8906 L26.0781,127.4688 C26.0781,127.0313 26.0625,126.9063 25.9688,126.75 C25.8125,126.4844 25.5313,126.3438 25.2344,126.3438 C24.9375,126.3438 24.7344,126.4375 24.5156,126.75 L24.3438,126.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="19" x="36" y="135.8467">A1</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="57" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="57" y1="155" y2="155"/></g><!--class B1--><g id="elem_B1"><rect fill="#F1F1F1" height="48" id="B1" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="51" x="7" y="7"/><ellipse cx="22" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,18.6719 C23.4063,18.2344 22.8125,18.0938 21.9375,18.0938 C19.3125,18.0938 17.3125,20.1719 17.3125,22.8906 L17.3125,24.0156 C17.3125,26.5938 19.4219,28.4844 22.3125,28.4844 C23.5313,28.4844 24.6875,28.1875 25.4375,27.6406 C26.0156,27.2344 26.3438,26.7813 26.3438,26.3906 C26.3438,25.9375 25.9531,25.5469 25.4844,25.5469 C25.2656,25.5469 25.0625,25.625 24.875,25.8125 C24.4219,26.2969 24.4219,26.2969 24.2344,26.3906 C23.8125,26.6563 23.125,26.7813 22.3594,26.7813 C20.3125,26.7813 19.0156,25.6875 19.0156,23.9844 L19.0156,22.8906 C19.0156,21.1094 20.2656,19.7969 22,19.7969 C22.5781,19.7969 23.1875,19.9531 23.6563,20.2031 C24.1406,20.4844 24.3125,20.7031 24.4063,21.1094 C24.4688,21.5156 24.5,21.6406 24.6406,21.7656 C24.7813,21.9063 25.0156,22.0156 25.2344,22.0156 C25.5,22.0156 25.7656,21.875 25.9375,21.6563 C26.0469,21.5 26.0781,21.3125 26.0781,20.8906 L26.0781,19.4688 C26.0781,19.0313 26.0625,18.9063 25.9688,18.75 C25.8125,18.4844 25.5313,18.3438 25.2344,18.3438 C24.9375,18.3438 24.7344,18.4375 24.5156,18.75 L24.3438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="19" x="36" y="27.8467">B1</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="57" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="57" y1="47" y2="47"/></g><!--class A2--><g id="elem_A2"><rect fill="#F1F1F1" height="48" id="A2" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="50" x="93.5" y="7"/><ellipse cx="108.5" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M110.8438,18.6719 C109.9063,18.2344 109.3125,18.0938 108.4375,18.0938 C105.8125,18.0938 103.8125,20.1719 103.8125,22.8906 L103.8125,24.0156 C103.8125,26.5938 105.9219,28.4844 108.8125,28.4844 C110.0313,28.4844 111.1875,28.1875 111.9375,27.6406 C112.5156,27.2344 112.8438,26.7813 112.8438,26.3906 C112.8438,25.9375 112.4531,25.5469 111.9844,25.5469 C111.7656,25.5469 111.5625,25.625 111.375,25.8125 C110.9219,26.2969 110.9219,26.2969 110.7344,26.3906 C110.3125,26.6563 109.625,26.7813 108.8594,26.7813 C106.8125,26.7813 105.5156,25.6875 105.5156,23.9844 L105.5156,22.8906 C105.5156,21.1094 106.7656,19.7969 108.5,19.7969 C109.0781,19.7969 109.6875,19.9531 110.1563,20.2031 C110.6406,20.4844 110.8125,20.7031 110.9063,21.1094 C110.9688,21.5156 111,21.6406 111.1406,21.7656 C111.2813,21.9063 111.5156,22.0156 111.7344,22.0156 C112,22.0156 112.2656,21.875 112.4375,21.6563 C112.5469,21.5 112.5781,21.3125 112.5781,20.8906 L112.5781,19.4688 C112.5781,19.0313 112.5625,18.9063 112.4688,18.75 C112.3125,18.4844 112.0313,18.3438 111.7344,18.3438 C111.4375,18.3438 111.2344,18.4375 111.0156,18.75 L110.8438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="18" x="122.5" y="27.8467">A2</text><line style="stroke:#181818;stroke-width:0.5;" x1="94.5" x2="142.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="94.5" x2="142.5" y1="47" y2="47"/></g><!--class B2--><g id="elem_B2"><rect fill="#F1F1F1" height="48" id="B2" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="50" x="93.5" y="115"/><ellipse cx="108.5" cy="131" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M110.8438,126.6719 C109.9063,126.2344 109.3125,126.0938 108.4375,126.0938 C105.8125,126.0938 103.8125,128.1719 103.8125,130.8906 L103.8125,132.0156 C103.8125,134.5938 105.9219,136.4844 108.8125,136.4844 C110.0313,136.4844 111.1875,136.1875 111.9375,135.6406 C112.5156,135.2344 112.8438,134.7813 112.8438,134.3906 C112.8438,133.9375 112.4531,133.5469 111.9844,133.5469 C111.7656,133.5469 111.5625,133.625 111.375,133.8125 C110.9219,134.2969 110.9219,134.2969 110.7344,134.3906 C110.3125,134.6563 109.625,134.7813 108.8594,134.7813 C106.8125,134.7813 105.5156,133.6875 105.5156,131.9844 L105.5156,130.8906 C105.5156,129.1094 106.7656,127.7969 108.5,127.7969 C109.0781,127.7969 109.6875,127.9531 110.1563,128.2031 C110.6406,128.4844 110.8125,128.7031 110.9063,129.1094 C110.9688,129.5156 111,129.6406 111.1406,129.7656 C111.2813,129.9063 111.5156,130.0156 111.7344,130.0156 C112,130.0156 112.2656,129.875 112.4375,129.6563 C112.5469,129.5 112.5781,129.3125 112.5781,128.8906 L112.5781,127.4688 C112.5781,127.0313 112.5625,126.9063 112.4688,126.75 C112.3125,126.4844 112.0313,126.3438 111.7344,126.3438 C111.4375,126.3438 111.2344,126.4375 111.0156,126.75 L110.8438,126.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="18" x="122.5" y="135.8467">B2</text><line style="stroke:#181818;stroke-width:0.5;" x1="94.5" x2="142.5" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="94.5" x2="142.5" y1="155" y2="155"/></g><!--reverse link B1 to A1--><g id="link_B1_A1"><path codeline="2" d="M32.5,61 C32.5,78.6584 32.5,96.9408 32.5,114.6784 " fill="none" id="B1-backto-A1" style="stroke:#008000;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="#008000" points="32.5,55,28.5,64,32.5,60,36.5,64,32.5,55" style="stroke:#008000;stroke-width:1.0;"/></g><!--link A2 to B2--><g id="link_A2_B2"><path codeline="3" d="M118.5,55 C118.5,72.6584 118.5,90.9408 118.5,108.6784 " fill="none" id="A2-to-B2" style="stroke:#FF00FF;stroke-width:2.0;"/><polygon fill="#FF00FF" points="118.5,114.6784,122.5,105.6784,118.5,109.6784,114.5,105.6784,118.5,114.6784" style="stroke:#FF00FF;stroke-width:2.0;"/></g><!--SRC=[Iyv9B2vMS3JaSZHKq8rEIIpEI4tHKKulIatDYoqjqBLJS09A6G6bal9pW19fQGO6QMcn874Z0000]--></g></svg>

<p>也可以使用如下写法：</p>
<figure class="highlight text"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">A --&gt; B #blue;line.dashed;text:blue : 连接线</span><br></pre></td></tr></table></figure>

<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="187px" preserveAspectRatio="none" style="width:76px;height:187px;background:#FFFFFF;" version="1.1" viewBox="0 0 76 187" width="76px" zoomAndPan="magnify"><defs/><g><!--class A--><g id="elem_A"><rect fill="#F1F1F1" height="48" id="A" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="42" x="7" y="7"/><ellipse cx="22" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,18.6719 C23.4063,18.2344 22.8125,18.0938 21.9375,18.0938 C19.3125,18.0938 17.3125,20.1719 17.3125,22.8906 L17.3125,24.0156 C17.3125,26.5938 19.4219,28.4844 22.3125,28.4844 C23.5313,28.4844 24.6875,28.1875 25.4375,27.6406 C26.0156,27.2344 26.3438,26.7813 26.3438,26.3906 C26.3438,25.9375 25.9531,25.5469 25.4844,25.5469 C25.2656,25.5469 25.0625,25.625 24.875,25.8125 C24.4219,26.2969 24.4219,26.2969 24.2344,26.3906 C23.8125,26.6563 23.125,26.7813 22.3594,26.7813 C20.3125,26.7813 19.0156,25.6875 19.0156,23.9844 L19.0156,22.8906 C19.0156,21.1094 20.2656,19.7969 22,19.7969 C22.5781,19.7969 23.1875,19.9531 23.6563,20.2031 C24.1406,20.4844 24.3125,20.7031 24.4063,21.1094 C24.4688,21.5156 24.5,21.6406 24.6406,21.7656 C24.7813,21.9063 25.0156,22.0156 25.2344,22.0156 C25.5,22.0156 25.7656,21.875 25.9375,21.6563 C26.0469,21.5 26.0781,21.3125 26.0781,20.8906 L26.0781,19.4688 C26.0781,19.0313 26.0625,18.9063 25.9688,18.75 C25.8125,18.4844 25.5313,18.3438 25.2344,18.3438 C24.9375,18.3438 24.7344,18.4375 24.5156,18.75 L24.3438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="36" y="27.8467">A</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="48" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="48" y1="47" y2="47"/></g><!--class B--><g id="elem_B"><rect fill="#F1F1F1" height="48" id="B" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="42" x="7" y="132"/><ellipse cx="22" cy="148" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,143.6719 C23.4063,143.2344 22.8125,143.0938 21.9375,143.0938 C19.3125,143.0938 17.3125,145.1719 17.3125,147.8906 L17.3125,149.0156 C17.3125,151.5938 19.4219,153.4844 22.3125,153.4844 C23.5313,153.4844 24.6875,153.1875 25.4375,152.6406 C26.0156,152.2344 26.3438,151.7813 26.3438,151.3906 C26.3438,150.9375 25.9531,150.5469 25.4844,150.5469 C25.2656,150.5469 25.0625,150.625 24.875,150.8125 C24.4219,151.2969 24.4219,151.2969 24.2344,151.3906 C23.8125,151.6563 23.125,151.7813 22.3594,151.7813 C20.3125,151.7813 19.0156,150.6875 19.0156,148.9844 L19.0156,147.8906 C19.0156,146.1094 20.2656,144.7969 22,144.7969 C22.5781,144.7969 23.1875,144.9531 23.6563,145.2031 C24.1406,145.4844 24.3125,145.7031 24.4063,146.1094 C24.4688,146.5156 24.5,146.6406 24.6406,146.7656 C24.7813,146.9063 25.0156,147.0156 25.2344,147.0156 C25.5,147.0156 25.7656,146.875 25.9375,146.6563 C26.0469,146.5 26.0781,146.3125 26.0781,145.8906 L26.0781,144.4688 C26.0781,144.0313 26.0625,143.9063 25.9688,143.75 C25.8125,143.4844 25.5313,143.3438 25.2344,143.3438 C24.9375,143.3438 24.7344,143.4375 24.5156,143.75 L24.3438,143.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="10" x="36" y="152.8467">B</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="48" y1="164" y2="164"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="48" y1="172" y2="172"/></g><!--link A to B--><g id="link_A_B"><path codeline="1" d="M28,55.135 C28,77.126 28,104.0123 28,125.9684 " fill="none" id="A-to-B" style="stroke:#0000FF;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="#0000FF" points="28,131.9684,32,122.9684,28,126.9684,24,122.9684,28,131.9684" style="stroke:#0000FF;stroke-width:1.0;"/><text fill="#0000FF" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="39" x="29" y="98.0669">&#36830;&#25509;&#32447;</text></g><!--SRC=[SrJGrRLJS59GJiefJRNEoSnBrKj9BCv8JR4kIQqeiGA9AbWflDW_xrdVqkUxzWC0]--></g></svg>

<h2 id="调整布局"><a href="#调整布局" class="headerlink" title="调整布局"></a>调整布局</h2><p>PlantUML绘图会自动布局，但是如果想要手动对布局进行调整就很不方便，只能进行微调，没法做到精细的调整。</p>
<h3 id="改变连接线方向"><a href="#改变连接线方向" class="headerlink" title="改变连接线方向"></a>改变连接线方向</h3>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/32780962.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/863074da.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/863074da.html" class="post-title-link" itemprop="url">Fresco源码详解</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-08-29 21:44:18" itemprop="dateCreated datePublished" datetime="2023-08-29T21:44:18+08:00">2023-08-29</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-10-18 15:40:44" itemprop="dateModified" datetime="2023-10-18T15:40:44+08:00">2023-10-18</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">本文基于Fresco 3.0.0，对Fresco源码进行了详细的解析。</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <!-- 
`com.facebook.imagepipeline.image.EncodedImage#getInputStream`是什么？
`com.facebook.imagepipeline.platform.DefaultDecoder#decodeFromStream`会首先通过`mDecodeBuffers.acquire()`获取byteBuffer，如果获取不到就通过`ByteBuffer.allocate`来申请内存。 
-->

<p>通过Fresco加载图片，最简单的方式是通过<code>SimpleDraweeView</code>来展示图片，示例代码如下：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">com.facebook.drawee.view.SimpleDraweeView</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:id</span>=<span class="string">&quot;@+id/my_image_view&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">&quot;130dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">&quot;130dp&quot;</span></span></span><br><span class="line"><span class="tag">    <span class="attr">fresco:placeholderImage</span>=<span class="string">&quot;@drawable/my_drawable&quot;</span></span></span><br><span class="line"><span class="tag">  /&gt;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//示例代码在Fragment#onViewCreated中调用</span></span><br><span class="line"><span class="type">Uri</span> <span class="variable">uri</span> <span class="operator">=</span> Uri.parse(<span class="string">&quot;https://frescolib.org/static/sample-images/animal_a.png&quot;</span>);</span><br><span class="line"><span class="type">SimpleDraweeView</span> <span class="variable">draweeView</span> <span class="operator">=</span> (SimpleDraweeView) findViewById(R.id.my_image_view);</span><br><span class="line">draweeView.setImageURI(uri);</span><br></pre></td></tr></table></figure>

<p>先看一下<code>SimpleDraweeView</code>相关的类图结构：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="510px" preserveAspectRatio="none" style="width:903px;height:510px;background:#FFFFFF;" version="1.1" viewBox="0 0 903 510" width="903px" zoomAndPan="magnify"><defs/><g><!--class ImageView--><g id="elem_ImageView"><rect fill="#F1F1F1" height="48" id="ImageView" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="110" x="88.5" y="7"/><ellipse cx="103.5" cy="23" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M105.8438,18.6719 C104.9063,18.2344 104.3125,18.0938 103.4375,18.0938 C100.8125,18.0938 98.8125,20.1719 98.8125,22.8906 L98.8125,24.0156 C98.8125,26.5938 100.9219,28.4844 103.8125,28.4844 C105.0313,28.4844 106.1875,28.1875 106.9375,27.6406 C107.5156,27.2344 107.8438,26.7813 107.8438,26.3906 C107.8438,25.9375 107.4531,25.5469 106.9844,25.5469 C106.7656,25.5469 106.5625,25.625 106.375,25.8125 C105.9219,26.2969 105.9219,26.2969 105.7344,26.3906 C105.3125,26.6563 104.625,26.7813 103.8594,26.7813 C101.8125,26.7813 100.5156,25.6875 100.5156,23.9844 L100.5156,22.8906 C100.5156,21.1094 101.7656,19.7969 103.5,19.7969 C104.0781,19.7969 104.6875,19.9531 105.1563,20.2031 C105.6406,20.4844 105.8125,20.7031 105.9063,21.1094 C105.9688,21.5156 106,21.6406 106.1406,21.7656 C106.2813,21.9063 106.5156,22.0156 106.7344,22.0156 C107,22.0156 107.2656,21.875 107.4375,21.6563 C107.5469,21.5 107.5781,21.3125 107.5781,20.8906 L107.5781,19.4688 C107.5781,19.0313 107.5625,18.9063 107.4688,18.75 C107.3125,18.4844 107.0313,18.3438 106.7344,18.3438 C106.4375,18.3438 106.2344,18.4375 106.0156,18.75 L105.8438,18.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="78" x="117.5" y="27.8467">ImageView</text><line style="stroke:#181818;stroke-width:0.5;" x1="89.5" x2="197.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="89.5" x2="197.5" y1="47" y2="47"/></g><!--class DraweeView--><g id="elem_DraweeView"><rect codeline="3" fill="#F1F1F1" height="48" id="DraweeView" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="273" x="7" y="123"/><ellipse cx="22" cy="139" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.3438,134.6719 C23.4063,134.2344 22.8125,134.0938 21.9375,134.0938 C19.3125,134.0938 17.3125,136.1719 17.3125,138.8906 L17.3125,140.0156 C17.3125,142.5938 19.4219,144.4844 22.3125,144.4844 C23.5313,144.4844 24.6875,144.1875 25.4375,143.6406 C26.0156,143.2344 26.3438,142.7813 26.3438,142.3906 C26.3438,141.9375 25.9531,141.5469 25.4844,141.5469 C25.2656,141.5469 25.0625,141.625 24.875,141.8125 C24.4219,142.2969 24.4219,142.2969 24.2344,142.3906 C23.8125,142.6563 23.125,142.7813 22.3594,142.7813 C20.3125,142.7813 19.0156,141.6875 19.0156,139.9844 L19.0156,138.8906 C19.0156,137.1094 20.2656,135.7969 22,135.7969 C22.5781,135.7969 23.1875,135.9531 23.6563,136.2031 C24.1406,136.4844 24.3125,136.7031 24.4063,137.1094 C24.4688,137.5156 24.5,137.6406 24.6406,137.7656 C24.7813,137.9063 25.0156,138.0156 25.2344,138.0156 C25.5,138.0156 25.7656,137.875 25.9375,137.6563 C26.0469,137.5 26.0781,137.3125 26.0781,136.8906 L26.0781,135.4688 C26.0781,135.0313 26.0625,134.9063 25.9688,134.75 C25.8125,134.4844 25.5313,134.3438 25.2344,134.3438 C24.9375,134.3438 24.7344,134.4375 24.5156,134.75 L24.3438,134.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="88" x="36" y="143.8467">DraweeView</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="151" x="132" y="120"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="149" x="133" y="132.1387">GenericDraweeHierarchy</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="279" y1="155" y2="155"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="279" y1="163" y2="163"/></g><!--class GenericDraweeView--><g id="elem_GenericDraweeView"><rect fill="#F1F1F1" height="48" id="GenericDraweeView" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="176" x="79.5" y="239"/><ellipse cx="94.5" cy="255" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M96.8438,250.6719 C95.9063,250.2344 95.3125,250.0938 94.4375,250.0938 C91.8125,250.0938 89.8125,252.1719 89.8125,254.8906 L89.8125,256.0156 C89.8125,258.5938 91.9219,260.4844 94.8125,260.4844 C96.0313,260.4844 97.1875,260.1875 97.9375,259.6406 C98.5156,259.2344 98.8438,258.7813 98.8438,258.3906 C98.8438,257.9375 98.4531,257.5469 97.9844,257.5469 C97.7656,257.5469 97.5625,257.625 97.375,257.8125 C96.9219,258.2969 96.9219,258.2969 96.7344,258.3906 C96.3125,258.6563 95.625,258.7813 94.8594,258.7813 C92.8125,258.7813 91.5156,257.6875 91.5156,255.9844 L91.5156,254.8906 C91.5156,253.1094 92.7656,251.7969 94.5,251.7969 C95.0781,251.7969 95.6875,251.9531 96.1563,252.2031 C96.6406,252.4844 96.8125,252.7031 96.9063,253.1094 C96.9688,253.5156 97,253.6406 97.1406,253.7656 C97.2813,253.9063 97.5156,254.0156 97.7344,254.0156 C98,254.0156 98.2656,253.875 98.4375,253.6563 C98.5469,253.5 98.5781,253.3125 98.5781,252.8906 L98.5781,251.4688 C98.5781,251.0313 98.5625,250.9063 98.4688,250.75 C98.3125,250.4844 98.0313,250.3438 97.7344,250.3438 C97.4375,250.3438 97.2344,250.4375 97.0156,250.75 L96.8438,250.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="144" x="108.5" y="259.8467">GenericDraweeView</text><line style="stroke:#181818;stroke-width:0.5;" x1="80.5" x2="254.5" y1="271" y2="271"/><line style="stroke:#181818;stroke-width:0.5;" x1="80.5" x2="254.5" y1="279" y2="279"/></g><!--class SimpleDraweeView--><g id="elem_SimpleDraweeView"><rect codeline="5" fill="#ADD8E6" height="48" id="SimpleDraweeView" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="170" x="96.5" y="347"/><ellipse cx="111.5" cy="363" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M113.8438,358.6719 C112.9063,358.2344 112.3125,358.0938 111.4375,358.0938 C108.8125,358.0938 106.8125,360.1719 106.8125,362.8906 L106.8125,364.0156 C106.8125,366.5938 108.9219,368.4844 111.8125,368.4844 C113.0313,368.4844 114.1875,368.1875 114.9375,367.6406 C115.5156,367.2344 115.8438,366.7813 115.8438,366.3906 C115.8438,365.9375 115.4531,365.5469 114.9844,365.5469 C114.7656,365.5469 114.5625,365.625 114.375,365.8125 C113.9219,366.2969 113.9219,366.2969 113.7344,366.3906 C113.3125,366.6563 112.625,366.7813 111.8594,366.7813 C109.8125,366.7813 108.5156,365.6875 108.5156,363.9844 L108.5156,362.8906 C108.5156,361.1094 109.7656,359.7969 111.5,359.7969 C112.0781,359.7969 112.6875,359.9531 113.1563,360.2031 C113.6406,360.4844 113.8125,360.7031 113.9063,361.1094 C113.9688,361.5156 114,361.6406 114.1406,361.7656 C114.2813,361.9063 114.5156,362.0156 114.7344,362.0156 C115,362.0156 115.2656,361.875 115.4375,361.6563 C115.5469,361.5 115.5781,361.3125 115.5781,360.8906 L115.5781,359.4688 C115.5781,359.0313 115.5625,358.9063 115.4688,358.75 C115.3125,358.4844 115.0313,358.3438 114.7344,358.3438 C114.4375,358.3438 114.2344,358.4375 114.0156,358.75 L113.8438,358.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="138" x="125.5" y="367.8467">SimpleDraweeView</text><line style="stroke:#181818;stroke-width:0.5;" x1="97.5" x2="265.5" y1="379" y2="379"/><line style="stroke:#181818;stroke-width:0.5;" x1="97.5" x2="265.5" y1="387" y2="387"/></g><!--class DraweeHierarchy--><g id="elem_DraweeHierarchy"><rect codeline="10" fill="#F1F1F1" height="64.2969" id="DraweeHierarchy" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="260" x="636.5" y="115"/><ellipse cx="699.75" cy="131" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M700.7031,127.7813 L702.4219,127.7813 C702.8125,127.7813 703,127.75 703.125,127.6719 C703.3906,127.5156 703.5313,127.2344 703.5313,126.9375 C703.5313,126.6719 703.4219,126.4063 703.1875,126.2344 C703.0156,126.125 702.875,126.0938 702.4219,126.0938 L697.2813,126.0938 C696.8438,126.0938 696.7188,126.1094 696.5625,126.2031 C696.3125,126.3594 696.1563,126.6563 696.1563,126.9375 C696.1563,127.2188 696.2969,127.4688 696.5156,127.6406 C696.6719,127.75 696.8594,127.7813 697.2813,127.7813 L699,127.7813 L699,134.2969 L697.2813,134.2969 C696.8438,134.2969 696.7188,134.3125 696.5625,134.4219 C696.3125,134.5781 696.1563,134.8594 696.1563,135.1563 C696.1563,135.4063 696.2969,135.6719 696.5156,135.8281 C696.6719,135.9531 696.875,136 697.2813,136 L702.4219,136 C703.1719,136 703.5313,135.7188 703.5313,135.1563 C703.5313,134.875 703.4219,134.625 703.1875,134.4531 C703.0156,134.3281 702.875,134.2969 702.4219,134.2969 L700.7031,134.2969 L700.7031,127.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="125" x="720.25" y="135.8467">DraweeHierarchy</text><line style="stroke:#181818;stroke-width:0.5;" x1="637.5" x2="895.5" y1="147" y2="147"/><line style="stroke:#181818;stroke-width:0.5;" x1="637.5" x2="895.5" y1="155" y2="155"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="248" x="642.5" y="171.9951">getTopLevelDrawable() : Drawable</text></g><!--class SettableDraweeHierarchy--><g id="elem_SettableDraweeHierarchy"><rect codeline="13" fill="#F1F1F1" height="48" id="SettableDraweeHierarchy" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="216" x="658.5" y="239"/><ellipse cx="673.5" cy="255" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M674.4531,251.7813 L676.1719,251.7813 C676.5625,251.7813 676.75,251.75 676.875,251.6719 C677.1406,251.5156 677.2813,251.2344 677.2813,250.9375 C677.2813,250.6719 677.1719,250.4063 676.9375,250.2344 C676.7656,250.125 676.625,250.0938 676.1719,250.0938 L671.0313,250.0938 C670.5938,250.0938 670.4688,250.1094 670.3125,250.2031 C670.0625,250.3594 669.9063,250.6563 669.9063,250.9375 C669.9063,251.2188 670.0469,251.4688 670.2656,251.6406 C670.4219,251.75 670.6094,251.7813 671.0313,251.7813 L672.75,251.7813 L672.75,258.2969 L671.0313,258.2969 C670.5938,258.2969 670.4688,258.3125 670.3125,258.4219 C670.0625,258.5781 669.9063,258.8594 669.9063,259.1563 C669.9063,259.4063 670.0469,259.6719 670.2656,259.8281 C670.4219,259.9531 670.625,260 671.0313,260 L676.1719,260 C676.9219,260 677.2813,259.7188 677.2813,259.1563 C677.2813,258.875 677.1719,258.625 676.9375,258.4531 C676.7656,258.3281 676.625,258.2969 676.1719,258.2969 L674.4531,258.2969 L674.4531,251.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="184" x="687.5" y="259.8467">SettableDraweeHierarchy</text><line style="stroke:#181818;stroke-width:0.5;" x1="659.5" x2="873.5" y1="271" y2="271"/><line style="stroke:#181818;stroke-width:0.5;" x1="659.5" x2="873.5" y1="279" y2="279"/></g><!--class GenericDraweeHierarchy--><g id="elem_GenericDraweeHierarchy"><rect codeline="14" fill="#F1F1F1" height="48" id="GenericDraweeHierarchy" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="210" x="661.5" y="347"/><ellipse cx="676.5" cy="363" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M678.8438,358.6719 C677.9063,358.2344 677.3125,358.0938 676.4375,358.0938 C673.8125,358.0938 671.8125,360.1719 671.8125,362.8906 L671.8125,364.0156 C671.8125,366.5938 673.9219,368.4844 676.8125,368.4844 C678.0313,368.4844 679.1875,368.1875 679.9375,367.6406 C680.5156,367.2344 680.8438,366.7813 680.8438,366.3906 C680.8438,365.9375 680.4531,365.5469 679.9844,365.5469 C679.7656,365.5469 679.5625,365.625 679.375,365.8125 C678.9219,366.2969 678.9219,366.2969 678.7344,366.3906 C678.3125,366.6563 677.625,366.7813 676.8594,366.7813 C674.8125,366.7813 673.5156,365.6875 673.5156,363.9844 L673.5156,362.8906 C673.5156,361.1094 674.7656,359.7969 676.5,359.7969 C677.0781,359.7969 677.6875,359.9531 678.1563,360.2031 C678.6406,360.4844 678.8125,360.7031 678.9063,361.1094 C678.9688,361.5156 679,361.6406 679.1406,361.7656 C679.2813,361.9063 679.5156,362.0156 679.7344,362.0156 C680,362.0156 680.2656,361.875 680.4375,361.6563 C680.5469,361.5 680.5781,361.3125 680.5781,360.8906 L680.5781,359.4688 C680.5781,359.0313 680.5625,358.9063 680.4688,358.75 C680.3125,358.4844 680.0313,358.3438 679.7344,358.3438 C679.4375,358.3438 679.2344,358.4375 679.0156,358.75 L678.8438,358.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="178" x="690.5" y="367.8467">GenericDraweeHierarchy</text><line style="stroke:#181818;stroke-width:0.5;" x1="662.5" x2="870.5" y1="379" y2="379"/><line style="stroke:#181818;stroke-width:0.5;" x1="662.5" x2="870.5" y1="387" y2="387"/></g><!--class DraweeController--><g id="elem_DraweeController"><rect codeline="18" fill="#F1F1F1" height="48" id="DraweeController" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="158" x="353.5" y="239"/><ellipse cx="368.5" cy="255" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M369.4531,251.7813 L371.1719,251.7813 C371.5625,251.7813 371.75,251.75 371.875,251.6719 C372.1406,251.5156 372.2813,251.2344 372.2813,250.9375 C372.2813,250.6719 372.1719,250.4063 371.9375,250.2344 C371.7656,250.125 371.625,250.0938 371.1719,250.0938 L366.0313,250.0938 C365.5938,250.0938 365.4688,250.1094 365.3125,250.2031 C365.0625,250.3594 364.9063,250.6563 364.9063,250.9375 C364.9063,251.2188 365.0469,251.4688 365.2656,251.6406 C365.4219,251.75 365.6094,251.7813 366.0313,251.7813 L367.75,251.7813 L367.75,258.2969 L366.0313,258.2969 C365.5938,258.2969 365.4688,258.3125 365.3125,258.4219 C365.0625,258.5781 364.9063,258.8594 364.9063,259.1563 C364.9063,259.4063 365.0469,259.6719 365.2656,259.8281 C365.4219,259.9531 365.625,260 366.0313,260 L371.1719,260 C371.9219,260 372.2813,259.7188 372.2813,259.1563 C372.2813,258.875 372.1719,258.625 371.9375,258.4531 C371.7656,258.3281 371.625,258.2969 371.1719,258.2969 L369.4531,258.2969 L369.4531,251.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="126" x="382.5" y="259.8467">DraweeController</text><line style="stroke:#181818;stroke-width:0.5;" x1="354.5" x2="510.5" y1="271" y2="271"/><line style="stroke:#181818;stroke-width:0.5;" x1="354.5" x2="510.5" y1="279" y2="279"/></g><!--class DraweeHolder--><g id="elem_DraweeHolder"><rect codeline="21" fill="#F1F1F1" height="48" id="DraweeHolder" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="286" x="315.5" y="123"/><ellipse cx="330.5" cy="139" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M332.8438,134.6719 C331.9063,134.2344 331.3125,134.0938 330.4375,134.0938 C327.8125,134.0938 325.8125,136.1719 325.8125,138.8906 L325.8125,140.0156 C325.8125,142.5938 327.9219,144.4844 330.8125,144.4844 C332.0313,144.4844 333.1875,144.1875 333.9375,143.6406 C334.5156,143.2344 334.8438,142.7813 334.8438,142.3906 C334.8438,141.9375 334.4531,141.5469 333.9844,141.5469 C333.7656,141.5469 333.5625,141.625 333.375,141.8125 C332.9219,142.2969 332.9219,142.2969 332.7344,142.3906 C332.3125,142.6563 331.625,142.7813 330.8594,142.7813 C328.8125,142.7813 327.5156,141.6875 327.5156,139.9844 L327.5156,138.8906 C327.5156,137.1094 328.7656,135.7969 330.5,135.7969 C331.0781,135.7969 331.6875,135.9531 332.1563,136.2031 C332.6406,136.4844 332.8125,136.7031 332.9063,137.1094 C332.9688,137.5156 333,137.6406 333.1406,137.7656 C333.2813,137.9063 333.5156,138.0156 333.7344,138.0156 C334,138.0156 334.2656,137.875 334.4375,137.6563 C334.5469,137.5 334.5781,137.3125 334.5781,136.8906 L334.5781,135.4688 C334.5781,135.0313 334.5625,134.9063 334.4688,134.75 C334.3125,134.4844 334.0313,134.3438 333.7344,134.3438 C333.4375,134.3438 333.2344,134.4375 333.0156,134.75 L332.8438,134.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="101" x="344.5" y="143.8467">DraweeHolder</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="151" x="453.5" y="120"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="149" x="454.5" y="132.1387">GenericDraweeHierarchy</text><line style="stroke:#181818;stroke-width:0.5;" x1="316.5" x2="600.5" y1="155" y2="155"/><line style="stroke:#181818;stroke-width:0.5;" x1="316.5" x2="600.5" y1="163" y2="163"/></g><!--class VisibilityCallback--><g id="elem_VisibilityCallback"><rect codeline="25" fill="#F1F1F1" height="48" id="VisibilityCallback" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="152" x="382.5" y="7"/><ellipse cx="397.5" cy="23" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M398.4531,19.7813 L400.1719,19.7813 C400.5625,19.7813 400.75,19.75 400.875,19.6719 C401.1406,19.5156 401.2813,19.2344 401.2813,18.9375 C401.2813,18.6719 401.1719,18.4063 400.9375,18.2344 C400.7656,18.125 400.625,18.0938 400.1719,18.0938 L395.0313,18.0938 C394.5938,18.0938 394.4688,18.1094 394.3125,18.2031 C394.0625,18.3594 393.9063,18.6563 393.9063,18.9375 C393.9063,19.2188 394.0469,19.4688 394.2656,19.6406 C394.4219,19.75 394.6094,19.7813 395.0313,19.7813 L396.75,19.7813 L396.75,26.2969 L395.0313,26.2969 C394.5938,26.2969 394.4688,26.3125 394.3125,26.4219 C394.0625,26.5781 393.9063,26.8594 393.9063,27.1563 C393.9063,27.4063 394.0469,27.6719 394.2656,27.8281 C394.4219,27.9531 394.625,28 395.0313,28 L400.1719,28 C400.9219,28 401.2813,27.7188 401.2813,27.1563 C401.2813,26.875 401.1719,26.625 400.9375,26.4531 C400.7656,26.3281 400.625,26.2969 400.1719,26.2969 L398.4531,26.2969 L398.4531,19.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="120" x="411.5" y="27.8467">VisibilityCallback</text><line style="stroke:#181818;stroke-width:0.5;" x1="383.5" x2="533.5" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="383.5" x2="533.5" y1="47" y2="47"/></g><!--class RootDrawable--><g id="elem_RootDrawable"><rect fill="#F1F1F1" height="48" id="RootDrawable" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="134" x="699.5" y="455"/><ellipse cx="714.5" cy="471" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M716.8438,466.6719 C715.9063,466.2344 715.3125,466.0938 714.4375,466.0938 C711.8125,466.0938 709.8125,468.1719 709.8125,470.8906 L709.8125,472.0156 C709.8125,474.5938 711.9219,476.4844 714.8125,476.4844 C716.0313,476.4844 717.1875,476.1875 717.9375,475.6406 C718.5156,475.2344 718.8438,474.7813 718.8438,474.3906 C718.8438,473.9375 718.4531,473.5469 717.9844,473.5469 C717.7656,473.5469 717.5625,473.625 717.375,473.8125 C716.9219,474.2969 716.9219,474.2969 716.7344,474.3906 C716.3125,474.6563 715.625,474.7813 714.8594,474.7813 C712.8125,474.7813 711.5156,473.6875 711.5156,471.9844 L711.5156,470.8906 C711.5156,469.1094 712.7656,467.7969 714.5,467.7969 C715.0781,467.7969 715.6875,467.9531 716.1563,468.2031 C716.6406,468.4844 716.8125,468.7031 716.9063,469.1094 C716.9688,469.5156 717,469.6406 717.1406,469.7656 C717.2813,469.9063 717.5156,470.0156 717.7344,470.0156 C718,470.0156 718.2656,469.875 718.4375,469.6563 C718.5469,469.5 718.5781,469.3125 718.5781,468.8906 L718.5781,467.4688 C718.5781,467.0313 718.5625,466.9063 718.4688,466.75 C718.3125,466.4844 718.0313,466.3438 717.7344,466.3438 C717.4375,466.3438 717.2344,466.4375 717.0156,466.75 L716.8438,466.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="102" x="728.5" y="475.8467">RootDrawable</text><line style="stroke:#181818;stroke-width:0.5;" x1="700.5" x2="832.5" y1="487" y2="487"/><line style="stroke:#181818;stroke-width:0.5;" x1="700.5" x2="832.5" y1="495" y2="495"/></g><!--class AbstractDraweeController--><g id="elem_AbstractDraweeController"><rect codeline="32" fill="#F1F1F1" height="48" id="AbstractDraweeController" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="217" x="324" y="347"/><ellipse cx="339" cy="363" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M341.0781,364.8125 L341.4688,365.7969 L341.0781,365.7969 C340.625,365.7969 340.5156,365.8125 340.3594,365.9219 C340.1094,366.0781 339.9531,366.3594 339.9531,366.6563 C339.9531,366.9219 340.0938,367.1719 340.3125,367.3281 C340.4531,367.4531 340.6563,367.5 341.0781,367.5 L343.4375,367.5 C343.7969,367.5 344.0156,367.4688 344.1563,367.375 C344.4063,367.2344 344.5625,366.9375 344.5625,366.6563 C344.5625,366.375 344.4219,366.125 344.2031,365.9688 C344.0313,365.8281 343.875,365.7969 343.4063,365.7969 L340.0156,357.5938 L336.3438,357.5938 C335.8906,357.5938 335.7656,357.6094 335.6094,357.7031 C335.3594,357.875 335.2031,358.1563 335.2031,358.4375 C335.2031,358.7188 335.3438,358.9688 335.5625,359.1406 C335.7344,359.25 335.9063,359.2813 336.3438,359.2813 L337.4219,359.2813 L334.7813,365.7969 C334.3594,365.7969 334.2031,365.8125 334.0469,365.9219 C333.7969,366.0781 333.6406,366.3594 333.6406,366.6563 C333.6406,367.2188 334.0156,367.5 334.7656,367.5 L337.0313,367.5 C337.3906,367.5 337.6094,367.4688 337.7344,367.375 C338,367.2344 338.1406,366.9375 338.1406,366.6563 C338.1406,366.375 338.0156,366.125 337.7969,365.9531 C337.625,365.8281 337.4844,365.7969 337.0313,365.7969 L336.6406,365.7969 L337.0313,364.8125 L341.0781,364.8125 Z M340.375,363.1094 L337.7031,363.1094 L339.0469,359.8438 L340.375,363.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="185" x="353" y="367.8467">AbstractDraweeController</text><line style="stroke:#181818;stroke-width:0.5;" x1="325" x2="540" y1="379" y2="379"/><line style="stroke:#181818;stroke-width:0.5;" x1="325" x2="540" y1="387" y2="387"/></g><!--class PipelineDraweeController--><g id="elem_PipelineDraweeController"><rect fill="#F1F1F1" height="48" id="PipelineDraweeController" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="217" x="324" y="455"/><ellipse cx="339" cy="471" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M341.3438,466.6719 C340.4063,466.2344 339.8125,466.0938 338.9375,466.0938 C336.3125,466.0938 334.3125,468.1719 334.3125,470.8906 L334.3125,472.0156 C334.3125,474.5938 336.4219,476.4844 339.3125,476.4844 C340.5313,476.4844 341.6875,476.1875 342.4375,475.6406 C343.0156,475.2344 343.3438,474.7813 343.3438,474.3906 C343.3438,473.9375 342.9531,473.5469 342.4844,473.5469 C342.2656,473.5469 342.0625,473.625 341.875,473.8125 C341.4219,474.2969 341.4219,474.2969 341.2344,474.3906 C340.8125,474.6563 340.125,474.7813 339.3594,474.7813 C337.3125,474.7813 336.0156,473.6875 336.0156,471.9844 L336.0156,470.8906 C336.0156,469.1094 337.2656,467.7969 339,467.7969 C339.5781,467.7969 340.1875,467.9531 340.6563,468.2031 C341.1406,468.4844 341.3125,468.7031 341.4063,469.1094 C341.4688,469.5156 341.5,469.6406 341.6406,469.7656 C341.7813,469.9063 342.0156,470.0156 342.2344,470.0156 C342.5,470.0156 342.7656,469.875 342.9375,469.6563 C343.0469,469.5 343.0781,469.3125 343.0781,468.8906 L343.0781,467.4688 C343.0781,467.0313 343.0625,466.9063 342.9688,466.75 C342.8125,466.4844 342.5313,466.3438 342.2344,466.3438 C341.9375,466.3438 341.7344,466.4375 341.5156,466.75 L341.3438,466.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="185" x="353" y="475.8467">PipelineDraweeController</text><line style="stroke:#181818;stroke-width:0.5;" x1="325" x2="540" y1="487" y2="487"/><line style="stroke:#181818;stroke-width:0.5;" x1="325" x2="540" y1="495" y2="495"/></g><!--reverse link ImageView to DraweeView--><g id="link_ImageView_DraweeView"><path codeline="2" d="M143.5,73.07 C143.5,92.848 143.5,103.196 143.5,122.965 " fill="none" id="ImageView-backto-DraweeView" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="143.5,55.07,137.5,73.07,149.5,73.07,143.5,55.07" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeView to GenericDraweeView--><g id="link_DraweeView_GenericDraweeView"><path codeline="4" d="M152.0654,188.6839 C156.2294,208.4619 158.489,219.196 162.65,238.965 " fill="none" id="DraweeView-backto-GenericDraweeView" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="148.357,171.07,146.1941,189.92,157.9367,187.4477,148.357,171.07" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link GenericDraweeView to SimpleDraweeView--><g id="link_GenericDraweeView_SimpleDraweeView"><path codeline="6" d="M172.8947,304.8451 C175.2267,322.5031 176.077,328.941 178.42,346.678 " fill="none" id="GenericDraweeView-backto-SimpleDraweeView" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="170.538,287,166.9464,305.6306,178.8431,304.0595,170.538,287" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link SettableDraweeHierarchy to GenericDraweeHierarchy--><g id="link_SettableDraweeHierarchy_GenericDraweeHierarchy"><path codeline="15" d="M766.5,305 C766.5,322.658 766.5,328.941 766.5,346.678 " fill="none" id="SettableDraweeHierarchy-backto-GenericDraweeHierarchy" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="766.5,287,760.5,305,772.5,305,766.5,287" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeHierarchy to SettableDraweeHierarchy--><g id="link_DraweeHierarchy_SettableDraweeHierarchy"><path codeline="19" d="M766.5,197.151 C766.5,216.005 766.5,221.647 766.5,238.845 " fill="none" id="DraweeHierarchy-backto-SettableDraweeHierarchy" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="766.5,179.151,760.5,197.151,772.5,197.151,766.5,179.151" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeHolder to DraweeController--><g id="link_DraweeHolder_DraweeController"><path codeline="22" d="M450.5705,182.7695 C446.0595,202.5475 442.262,219.196 437.754,238.965 " fill="none" id="DraweeHolder-backto-DraweeController" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="453.239,171.07,448.0049,176.0303,450.5705,182.7695,455.8046,177.8093,453.239,171.07" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeHolder to DraweeHierarchy--><g id="link_DraweeHolder_DraweeHierarchy"><path codeline="23" d="M613.672,147 C625.261,147 624.851,147 636.44,147 " fill="none" id="DraweeHolder-backto-DraweeHierarchy" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="601.672,147,607.672,151,613.672,147,607.672,143,601.672,147" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link VisibilityCallback to DraweeHolder--><g id="link_VisibilityCallback_DraweeHolder"><path codeline="26" d="M458.5,73.07 C458.5,92.848 458.5,103.196 458.5,122.965 " fill="none" id="VisibilityCallback-backto-DraweeHolder" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="458.5,55.07,452.5,73.07,464.5,73.07,458.5,55.07" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeView to DraweeHolder--><g id="link_DraweeView_DraweeHolder"><path codeline="27" d="M292.082,147 C303.814,147 303.546,147 315.278,147 " fill="none" id="DraweeView-backto-DraweeHolder" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="280.082,147,286.082,151,292.082,147,286.082,143,280.082,147" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link GenericDraweeHierarchy to RootDrawable--><g id="link_GenericDraweeHierarchy_RootDrawable"><path codeline="29" d="M766.5,407 C766.5,424.6584 766.5,436.9408 766.5,454.6784 " fill="none" id="GenericDraweeHierarchy-backto-RootDrawable" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="766.5,395,762.5,401,766.5,407,770.5,401,766.5,395" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeController to SimpleDraweeView--><g id="link_DraweeController_SimpleDraweeView"><path codeline="31" d="M372.5097,289.3343 C330.5527,307.0533 278.328,329.108 236.29,346.862 " fill="none" id="DraweeController-backto-SimpleDraweeView" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="378.037,287,368.1899,286.8165,373.4309,288.9452,371.3022,294.1863,378.037,287" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link DraweeController to AbstractDraweeController--><g id="link_DraweeController_AbstractDraweeController"><path codeline="33" d="M432.5,305 C432.5,322.658 432.5,328.941 432.5,346.678 " fill="none" id="DraweeController-backto-AbstractDraweeController" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="432.5,287,426.5,305,438.5,305,432.5,287" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AbstractDraweeController to PipelineDraweeController--><g id="link_AbstractDraweeController_PipelineDraweeController"><path codeline="34" d="M432.5,413 C432.5,430.6584 432.5,436.9408 432.5,454.6784 " fill="none" id="AbstractDraweeController-backto-PipelineDraweeController" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="432.5,395,426.5,413,438.5,413,432.5,395" style="stroke:#181818;stroke-width:1.0;"/></g><!--SRC=[TL91JiCm4BplArRY0fNy0LHLGaMYI1mGHRqxxf9OREF8SOaguEyuCMtSEBx5kpFZcOoTASbLPF4R49yFigITfWwNFqBWevKT3MU_KopRDXejdwWcgrMOR3HPQLLrMdde20ewLyWhkQq-D4mH_ePrMRc2Z-Gn2I_8JKdm2-366BfsP3-a8fnO6o8YUk2xQLxeYxW7o8BfzWxlyNpmSgF4bfphXnCf2FRdVm5aIBtxlUbgaUFv75FpQrCxQvZ9meoQoFg3kAwDuJtPR64n21UNtjEhpmXCRXjjxtIh2ytQdTQIkP3g4z9H_Bo2AaGbBoOhc3S-M7qpnbsAW-GvYMCZLcaUMRJEIkNmuVyZatWS1CTPU6uHQA-w8TOrJRT_]--></g></svg>

<h2 id="图片加载过程"><a href="#图片加载过程" class="headerlink" title="图片加载过程"></a>图片加载过程</h2><p>这个时序图是以文章开头的<code>SimpleDraweeView</code>的示例代码为例进行绘制。</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="1171px" preserveAspectRatio="none" style="width:1101px;height:1171px;background:#FFFFFF;" version="1.1" viewBox="0 0 1101 1171" width="1101px" zoomAndPan="magnify"><defs/><g><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="201" y="97.6953"/><rect fill="#FFFFFF" height="101.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="201" y="183.2578"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="206" y="220.3906"/><rect fill="#FFFFFF" height="473.8594" style="stroke:#181818;stroke-width:1.0;" width="10" x="386.5" y="515.5859"/><rect fill="#FFFFFF" height="406.7266" style="stroke:#181818;stroke-width:1.0;" width="10" x="391.5" y="582.7188"/><rect fill="#FFFFFF" height="278.1953" style="stroke:#181818;stroke-width:1.0;" width="10" x="396.5" y="682.1172"/><rect fill="#FFFFFF" height="108.3984" style="stroke:#181818;stroke-width:1.0;" width="10" x="386.5" y="1018.5781"/><rect fill="#FFFFFF" height="80.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="553.5" y="254.5234"/><rect fill="#FFFFFF" height="101.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="553.5" y="444.3203"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="558.5" y="481.4531"/><rect fill="#FFFFFF" height="244.0625" style="stroke:#181818;stroke-width:1.0;" width="10" x="851.5" y="716.25"/><rect fill="#FFFFFF" height="164.7969" style="stroke:#181818;stroke-width:1.0;" width="10" x="856.5" y="795.5156"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="206" x2="206" y1="36.2969" y2="1135.9766"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="391" x2="391" y1="136.3438" y2="1135.9766"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="558" x2="558" y1="36.2969" y2="1135.9766"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="730.5" x2="730.5" y1="36.2969" y2="1135.9766"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="856.5" x2="856.5" y1="36.2969" y2="1135.9766"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="1022" x2="1022" y1="840.6484" y2="1135.9766"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="152" x="130" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="138" x="137" y="24.9951">SimpleDraweeView</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="152" x="130" y="1134.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="138" x="137" y="1154.9717">SimpleDraweeView</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="199" x="292" y="1134.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="185" x="299" y="1154.9717">PipelineDraweeController</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="115" x="501" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="101" x="508" y="24.9951">DraweeHolder</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="115" x="501" y="1134.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="101" x="508" y="1154.9717">DraweeHolder</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="116" x="672.5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="102" x="679.5" y="24.9951">RootDrawable</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="116" x="672.5" y="1134.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="102" x="679.5" y="1154.9717">RootDrawable</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="116" x="798.5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="102" x="805.5" y="24.9951">ImagePipeline</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="116" x="798.5" y="1134.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="102" x="805.5" y="1154.9717">ImagePipeline</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="97" x="974" y="1134.9766"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="83" x="981" y="1154.9717">DataSource</text><rect fill="#FFFFFF" height="29.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="201" y="97.6953"/><rect fill="#FFFFFF" height="101.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="201" y="183.2578"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="206" y="220.3906"/><rect fill="#FFFFFF" height="473.8594" style="stroke:#181818;stroke-width:1.0;" width="10" x="386.5" y="515.5859"/><rect fill="#FFFFFF" height="406.7266" style="stroke:#181818;stroke-width:1.0;" width="10" x="391.5" y="582.7188"/><rect fill="#FFFFFF" height="278.1953" style="stroke:#181818;stroke-width:1.0;" width="10" x="396.5" y="682.1172"/><rect fill="#FFFFFF" height="108.3984" style="stroke:#181818;stroke-width:1.0;" width="10" x="386.5" y="1018.5781"/><rect fill="#FFFFFF" height="80.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="553.5" y="254.5234"/><rect fill="#FFFFFF" height="101.2656" style="stroke:#181818;stroke-width:1.0;" width="10" x="553.5" y="444.3203"/><rect fill="#FFFFFF" height="64.1328" style="stroke:#181818;stroke-width:1.0;" width="10" x="558.5" y="481.4531"/><rect fill="#FFFFFF" height="244.0625" style="stroke:#181818;stroke-width:1.0;" width="10" x="851.5" y="716.25"/><rect fill="#FFFFFF" height="164.7969" style="stroke:#181818;stroke-width:1.0;" width="10" x="856.5" y="795.5156"/><ellipse cx="7.5" cy="96.9453" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="189,93.6953,199,97.6953,189,101.6953,193,97.6953" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="195" y1="97.6953" y2="97.6953"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="96" x="15" y="62.3638">setImageURI();</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="174" x="15" y="77.4966">Framework.onViewCreated</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="39" x="15" y="92.6294">&#20013;&#35843;&#29992;</text><polygon fill="#181818" points="280,122.8281,290,126.8281,280,130.8281,284,126.8281" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="206" x2="286" y1="126.8281" y2="126.8281"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="26" x="213" y="121.7622">&#26500;&#36896;</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="199" x="292" y="105.6953"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="185" x="299" y="125.6904">PipelineDraweeController</text><ellipse cx="7.5" cy="182.5078" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="189,179.2578,199,183.2578,189,187.2578,193,183.2578" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="195" y1="183.2578" y2="183.2578"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="141" x="15" y="163.0591">onAttachedToWindow</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="78" x="15" y="178.1919">&#65288;&#29238;&#31867;&#26041;&#27861;&#65289;</text><line style="stroke:#181818;stroke-width:1.0;" x1="211" x2="258" y1="207.3906" y2="207.3906"/><line style="stroke:#181818;stroke-width:1.0;" x1="258" x2="258" y1="207.3906" y2="220.3906"/><line style="stroke:#181818;stroke-width:1.0;" x1="217" x2="258" y1="220.3906" y2="220.3906"/><polygon fill="#181818" points="227,216.3906,217,220.3906,227,224.3906,223,220.3906" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="58" x="223" y="202.3247">onAttach</text><polygon fill="#181818" points="541.5,250.5234,551.5,254.5234,541.5,258.5234,545.5,254.5234" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="216" x2="547.5" y1="254.5234" y2="254.5234"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="58" x="223" y="249.4575">onAttach</text><line style="stroke:#181818;stroke-width:1.0;" x1="563.5" x2="605.5" y1="333.7891" y2="333.7891"/><line style="stroke:#181818;stroke-width:1.0;" x1="605.5" x2="605.5" y1="333.7891" y2="346.7891"/><line style="stroke:#181818;stroke-width:1.0;" x1="558.5" x2="605.5" y1="346.7891" y2="346.7891"/><polygon fill="#181818" points="568.5,342.7891,558.5,346.7891,568.5,350.7891,564.5,346.7891" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="148" x="570.5" y="313.5903">&#27492;&#26102;&#36824;&#26410;&#35774;&#32622;visible,&#19981;&#20250;</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="129" x="570.5" y="328.7231">&#35843;&#29992;attachController</text><ellipse cx="7.5" cy="385.3047" fill="none" rx="4" ry="4" style="stroke:#181818;stroke-width:1.5;"/><polygon fill="#181818" points="194,382.0547,204,386.0547,194,390.0547,198,386.0547" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="12" x2="200" y1="386.0547" y2="386.0547"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="143" x="15" y="365.856">onVisibilityAggregated</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="146" x="15" y="380.9888">(&#29238;&#31867;ImageView&#30340;&#26041;&#27861;)</text><polygon fill="#181818" points="718.5,411.1875,728.5,415.1875,718.5,419.1875,722.5,415.1875" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="206" x2="724.5" y1="415.1875" y2="415.1875"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="61" x="213" y="410.1216">setVisible</text><polygon fill="#181818" points="574.5,440.3203,564.5,444.3203,574.5,448.3203,570.5,444.3203" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="568.5" x2="729.5" y1="444.3203" y2="444.3203"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="117" x="580.5" y="439.2544">onVisibilityChange</text><line style="stroke:#181818;stroke-width:1.0;" x1="563.5" x2="610.5" y1="468.4531" y2="468.4531"/><line style="stroke:#181818;stroke-width:1.0;" x1="610.5" x2="610.5" y1="468.4531" y2="481.4531"/><line style="stroke:#181818;stroke-width:1.0;" x1="569.5" x2="610.5" y1="481.4531" y2="481.4531"/><polygon fill="#181818" points="579.5,477.4531,569.5,481.4531,579.5,485.4531,575.5,481.4531" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="103" x="575.5" y="463.3872">attachController</text><polygon fill="#181818" points="407.5,511.5859,397.5,515.5859,407.5,519.5859,403.5,515.5859" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="401.5" x2="557.5" y1="515.5859" y2="515.5859"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="58" x="413.5" y="510.52">onAttach</text><line style="stroke:#181818;stroke-width:1.0;" x1="396.5" x2="443.5" y1="569.7188" y2="569.7188"/><line style="stroke:#181818;stroke-width:1.0;" x1="443.5" x2="443.5" y1="569.7188" y2="582.7188"/><line style="stroke:#181818;stroke-width:1.0;" x1="402.5" x2="443.5" y1="582.7188" y2="582.7188"/><polygon fill="#181818" points="412.5,578.7188,402.5,582.7188,412.5,586.7188,408.5,582.7188" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="97" x="408.5" y="564.6528">submitRequest</text><line style="stroke:#181818;stroke-width:1.0;" x1="401.5" x2="443.5" y1="631.9844" y2="631.9844"/><line style="stroke:#181818;stroke-width:1.0;" x1="443.5" x2="443.5" y1="631.9844" y2="644.9844"/><line style="stroke:#181818;stroke-width:1.0;" x1="402.5" x2="443.5" y1="644.9844" y2="644.9844"/><polygon fill="#181818" points="412.5,640.9844,402.5,644.9844,412.5,648.9844,408.5,644.9844" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="109" x="408.5" y="611.7856">getCachedImage</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="97" x="408.5" y="626.9185">&#33719;&#21462;&#32531;&#23384;Bitmap</text><line style="stroke:#181818;stroke-width:1.0;" x1="401.5" x2="448.5" y1="669.1172" y2="669.1172"/><line style="stroke:#181818;stroke-width:1.0;" x1="448.5" x2="448.5" y1="669.1172" y2="682.1172"/><line style="stroke:#181818;stroke-width:1.0;" x1="407.5" x2="448.5" y1="682.1172" y2="682.1172"/><polygon fill="#181818" points="417.5,678.1172,407.5,682.1172,417.5,686.1172,413.5,682.1172" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="96" x="413.5" y="664.0513">getDataSource</text><polygon fill="#181818" points="839.5,712.25,849.5,716.25,839.5,720.25,843.5,716.25" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="406.5" x2="845.5" y1="716.25" y2="716.25"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="130" x="413.5" y="711.1841">fetchDecodedImage</text><line style="stroke:#181818;stroke-width:1.0;" x1="861.5" x2="903.5" y1="745.3828" y2="745.3828"/><line style="stroke:#181818;stroke-width:1.0;" x1="903.5" x2="903.5" y1="745.3828" y2="758.3828"/><line style="stroke:#181818;stroke-width:1.0;" x1="862.5" x2="903.5" y1="758.3828" y2="758.3828"/><polygon fill="#181818" points="872.5,754.3828,862.5,758.3828,872.5,762.3828,868.5,758.3828" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="91" x="868.5" y="740.3169">&#29983;&#25104;&#29983;&#20135;&#32773;&#24207;&#21015;</text><line style="stroke:#181818;stroke-width:1.0;" x1="861.5" x2="908.5" y1="782.5156" y2="782.5156"/><line style="stroke:#181818;stroke-width:1.0;" x1="908.5" x2="908.5" y1="782.5156" y2="795.5156"/><line style="stroke:#181818;stroke-width:1.0;" x1="867.5" x2="908.5" y1="795.5156" y2="795.5156"/><polygon fill="#181818" points="877.5,791.5156,867.5,795.5156,877.5,799.5156,873.5,795.5156" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="142" x="873.5" y="777.4497">submitFetchRequest()</text><polygon fill="#181818" points="962,840.7813,972,844.7813,962,848.7813,966,844.7813" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="866.5" x2="968" y1="844.7813" y2="844.7813"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="873.5" y="824.5825">&#26500;&#36896;&#26102;&#20256;&#20837;</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="873.5" y="839.7153">&#29983;&#20135;&#32773;&#38431;&#21015;</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="97" x="974" y="811.4844"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="83" x="981" y="831.4795">DataSource</text><line style="stroke:#181818;stroke-width:1.0;" x1="1022.5" x2="1064.5" y1="889.0469" y2="889.0469"/><line style="stroke:#181818;stroke-width:1.0;" x1="1064.5" x2="1064.5" y1="889.0469" y2="902.0469"/><line style="stroke:#181818;stroke-width:1.0;" x1="1023.5" x2="1064.5" y1="902.0469" y2="902.0469"/><polygon fill="#181818" points="1033.5,898.0469,1023.5,902.0469,1033.5,906.0469,1029.5,902.0469" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="65" x="1029.5" y="868.8481">&#29983;&#20135;&#32773;&#38431;&#21015;</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="52" x="1029.5" y="883.981">&#21551;&#21160;&#25191;&#34892;</text><polygon fill="#181818" points="877.5,927.1797,867.5,931.1797,877.5,935.1797,873.5,931.1797" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="871.5" x2="1021.5" y1="931.1797" y2="931.1797"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="52" x="883.5" y="926.1138">&#36820;&#22238;&#23454;&#20363;</text><polygon fill="#181818" points="412.5,956.3125,402.5,960.3125,412.5,964.3125,408.5,960.3125" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" x1="406.5" x2="855.5" y1="960.3125" y2="960.3125"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="375" x="418.5" y="955.2466">&#36820;&#22238; DataSource&lt;CloseableReference&lt;CloseableImage&gt;&gt;</text><polygon fill="#181818" points="1010.5,985.4453,1020.5,989.4453,1010.5,993.4453,1014.5,989.4453" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="391.5" x2="1016.5" y1="989.4453" y2="989.4453"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="242" x="398.5" y="984.3794">&#160;&#160;subscribe(DataSubscriber)&#27880;&#20876;&#35746;&#38405;&#32773;</text><polygon fill="#181818" points="407.5,1014.5781,397.5,1018.5781,407.5,1022.5781,403.5,1018.5781" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="401.5" x2="1021.5" y1="1018.5781" y2="1018.5781"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="343" x="413.5" y="1013.5122">&#36820;&#22238;&#22270;&#29255;Bitmap&#12290;&#29238;&#31867;&#30340;onNewResultInternal()&#20250;&#34987;&#25191;&#34892;</text><line style="stroke:#181818;stroke-width:1.0;" x1="396.5" x2="438.5" y1="1047.7109" y2="1047.7109"/><line style="stroke:#181818;stroke-width:1.0;" x1="438.5" x2="438.5" y1="1047.7109" y2="1060.7109"/><line style="stroke:#181818;stroke-width:1.0;" x1="397.5" x2="438.5" y1="1060.7109" y2="1060.7109"/><polygon fill="#181818" points="407.5,1056.7109,397.5,1060.7109,407.5,1064.7109,403.5,1060.7109" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="102" x="403.5" y="1042.645">createDrawable</text><line style="stroke:#181818;stroke-width:1.0;" x1="396.5" x2="438.5" y1="1104.9766" y2="1104.9766"/><line style="stroke:#181818;stroke-width:1.0;" x1="438.5" x2="438.5" y1="1104.9766" y2="1117.9766"/><line style="stroke:#181818;stroke-width:1.0;" x1="397.5" x2="438.5" y1="1117.9766" y2="1117.9766"/><polygon fill="#181818" points="407.5,1113.9766,397.5,1117.9766,407.5,1121.9766,403.5,1117.9766" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="134" x="403.5" y="1084.7778">hierarchy.setImage()</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="52" x="403.5" y="1099.9106">&#26174;&#31034;&#22270;&#29255;</text><!--SRC=[dLLDJnD16BxlhzZ4nBJK4hruA8O4IuXSZ2cA1_OoR5_QYTkPEftIS2CAs2eAYGWD6422WMYe6X94hEN7sFtWn5zmThUbk_rOII-RxCpxFEypppCVKpGwB4_WJ5Q3KOOA09CO2d8a4fDpmCSpA0LF4kEXy912nXZAG86oPuEKs4Ln1eX3KY7rqoFh-qjpxL3gu17SZt0MD4mQet5AEAEQ1amU691Zih6zS36_AoK1gHpF2huEBP8qrLCY9IES8pKDoSVqAIP9Mb38PRLe5a_C7x-DzL_6yOVBQgchh6vyJRgk0FVl0TMIGhktUQ3ue3aVOtk7Q5IOSxHlR9nOvsNZunUhKZF_L6Pn3azhSAj- -hPUtLI8wpjoTBIixU6OBNdI9i0QvdCZgHI3b9jWo7NCYTikDJSNNFV2NQr8KChj4IIaEFjaqfKbUITwUDOI44yZae9W5snCn-hQ4JrtM2HYkzWj9o-5r1CVmEqSaFnq1lC4FCz3ZlV58Y990OyxEzWnNoJwxgU-icvMt-j7vVkOPr2sFsPReE0UHHnDq3nJ8P36QTuiSB0pmDNqAAWqsP0c-MiwG37PNDinYglYMpyxiEONzRCLlRZnFrZBo36xOyFDKBWJrrgAz-eG1wHUtTKNFolaglD5USVkx07uuOvKRwb2zDLl-kj3etHWVLhs0RkiqpfVqxUszSfslVQcNMPG9D7e5TYZvbvSepcmJqm2Pe01yGuvxCF3tgthQ-YTwDKtC7YVApTltBbxUyZzYanoAiFJ479AcdyiR1mVwalBLcNlehme3BoMWklK-DCAtDUD0BPgPkcLUqR-phzmhp1nSr7o40e9oEKrFauuC8AqK5ZSbjRUrqQ-VHvLrNdmclTRlonf30mnDJqts7nWGs656EMQkN_cBkaV]--></g></svg>

<p>上图中DateSource是一个<code>CloseableProducerToDataSourceAdapter</code>实例，如下图类图所示：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="428px" preserveAspectRatio="none" style="width:977px;height:428px;background:#FFFFFF;" version="1.1" viewBox="0 0 977 428" width="977px" zoomAndPan="magnify"><defs/><g><!--class DataSource--><g id="elem_DataSource"><rect codeline="1" fill="#F1F1F1" height="48" id="DataSource" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="349" x="478.5" y="10"/><ellipse cx="493.5" cy="26" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M495.8438,21.6719 C494.9063,21.2344 494.3125,21.0938 493.4375,21.0938 C490.8125,21.0938 488.8125,23.1719 488.8125,25.8906 L488.8125,27.0156 C488.8125,29.5938 490.9219,31.4844 493.8125,31.4844 C495.0313,31.4844 496.1875,31.1875 496.9375,30.6406 C497.5156,30.2344 497.8438,29.7813 497.8438,29.3906 C497.8438,28.9375 497.4531,28.5469 496.9844,28.5469 C496.7656,28.5469 496.5625,28.625 496.375,28.8125 C495.9219,29.2969 495.9219,29.2969 495.7344,29.3906 C495.3125,29.6563 494.625,29.7813 493.8594,29.7813 C491.8125,29.7813 490.5156,28.6875 490.5156,26.9844 L490.5156,25.8906 C490.5156,24.1094 491.7656,22.7969 493.5,22.7969 C494.0781,22.7969 494.6875,22.9531 495.1563,23.2031 C495.6406,23.4844 495.8125,23.7031 495.9063,24.1094 C495.9688,24.5156 496,24.6406 496.1406,24.7656 C496.2813,24.9063 496.5156,25.0156 496.7344,25.0156 C497,25.0156 497.2656,24.875 497.4375,24.6563 C497.5469,24.5 497.5781,24.3125 497.5781,23.8906 L497.5781,22.4688 C497.5781,22.0313 497.5625,21.9063 497.4688,21.75 C497.3125,21.4844 497.0313,21.3438 496.7344,21.3438 C496.4375,21.3438 496.2344,21.4375 496.0156,21.75 L495.8438,21.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="83" x="507.5" y="30.8467">DataSource</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="232" x="598.5" y="7"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="230" x="599.5" y="19.1387">CloseableReference&lt;CloseableImage&gt;</text><line style="stroke:#181818;stroke-width:0.5;" x1="479.5" x2="826.5" y1="42" y2="42"/><line style="stroke:#181818;stroke-width:0.5;" x1="479.5" x2="826.5" y1="50" y2="50"/></g><!--class Producer--><g id="elem_Producer"><rect codeline="2" fill="#F1F1F1" height="64.2969" id="Producer" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="401" x="12.5" y="357"/><ellipse cx="59.75" cy="373" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M62.0938,368.6719 C61.1563,368.2344 60.5625,368.0938 59.6875,368.0938 C57.0625,368.0938 55.0625,370.1719 55.0625,372.8906 L55.0625,374.0156 C55.0625,376.5938 57.1719,378.4844 60.0625,378.4844 C61.2813,378.4844 62.4375,378.1875 63.1875,377.6406 C63.7656,377.2344 64.0938,376.7813 64.0938,376.3906 C64.0938,375.9375 63.7031,375.5469 63.2344,375.5469 C63.0156,375.5469 62.8125,375.625 62.625,375.8125 C62.1719,376.2969 62.1719,376.2969 61.9844,376.3906 C61.5625,376.6563 60.875,376.7813 60.1094,376.7813 C58.0625,376.7813 56.7656,375.6875 56.7656,373.9844 L56.7656,372.8906 C56.7656,371.1094 58.0156,369.7969 59.75,369.7969 C60.3281,369.7969 60.9375,369.9531 61.4063,370.2031 C61.8906,370.4844 62.0625,370.7031 62.1563,371.1094 C62.2188,371.5156 62.25,371.6406 62.3906,371.7656 C62.5313,371.9063 62.7656,372.0156 62.9844,372.0156 C63.25,372.0156 63.5156,371.875 63.6875,371.6563 C63.7969,371.5 63.8281,371.3125 63.8281,370.8906 L63.8281,369.4688 C63.8281,369.0313 63.8125,368.9063 63.7188,368.75 C63.5625,368.4844 63.2813,368.3438 62.9844,368.3438 C62.6875,368.3438 62.4844,368.4375 62.2656,368.75 L62.0938,368.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="64" x="80.25" y="377.8467">Producer</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="232" x="184.5" y="354"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="230" x="185.5" y="366.1387">CloseableReference&lt;CloseableImage&gt;</text><line style="stroke:#181818;stroke-width:0.5;" x1="13.5" x2="412.5" y1="389" y2="389"/><line style="stroke:#181818;stroke-width:0.5;" x1="13.5" x2="412.5" y1="397" y2="397"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="389" x="18.5" y="413.9951">void produceResults(Consumer&lt;T&gt;, ProducerContext)</text></g><!--class AbstractDataSource--><g id="elem_AbstractDataSource"><rect codeline="5" fill="#F1F1F1" height="48" id="AbstractDataSource" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="409" x="448.5" y="119"/><ellipse cx="463.5" cy="135" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M465.5781,136.8125 L465.9688,137.7969 L465.5781,137.7969 C465.125,137.7969 465.0156,137.8125 464.8594,137.9219 C464.6094,138.0781 464.4531,138.3594 464.4531,138.6563 C464.4531,138.9219 464.5938,139.1719 464.8125,139.3281 C464.9531,139.4531 465.1563,139.5 465.5781,139.5 L467.9375,139.5 C468.2969,139.5 468.5156,139.4688 468.6563,139.375 C468.9063,139.2344 469.0625,138.9375 469.0625,138.6563 C469.0625,138.375 468.9219,138.125 468.7031,137.9688 C468.5313,137.8281 468.375,137.7969 467.9063,137.7969 L464.5156,129.5938 L460.8438,129.5938 C460.3906,129.5938 460.2656,129.6094 460.1094,129.7031 C459.8594,129.875 459.7031,130.1563 459.7031,130.4375 C459.7031,130.7188 459.8438,130.9688 460.0625,131.1406 C460.2344,131.25 460.4063,131.2813 460.8438,131.2813 L461.9219,131.2813 L459.2813,137.7969 C458.8594,137.7969 458.7031,137.8125 458.5469,137.9219 C458.2969,138.0781 458.1406,138.3594 458.1406,138.6563 C458.1406,139.2188 458.5156,139.5 459.2656,139.5 L461.5313,139.5 C461.8906,139.5 462.1094,139.4688 462.2344,139.375 C462.5,139.2344 462.6406,138.9375 462.6406,138.6563 C462.6406,138.375 462.5156,138.125 462.2969,137.9531 C462.125,137.8281 461.9844,137.7969 461.5313,137.7969 L461.1406,137.7969 L461.5313,136.8125 L465.5781,136.8125 Z M464.875,135.1094 L462.2031,135.1094 L463.5469,131.8438 L464.875,135.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="143" x="477.5" y="139.8467">AbstractDataSource</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="232" x="628.5" y="116"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="230" x="629.5" y="128.1387">CloseableReference&lt;CloseableImage&gt;</text><line style="stroke:#181818;stroke-width:0.5;" x1="449.5" x2="856.5" y1="151" y2="151"/><line style="stroke:#181818;stroke-width:0.5;" x1="449.5" x2="856.5" y1="159" y2="159"/></g><!--class AbstractProducerToDataSourceAdapter--><g id="elem_AbstractProducerToDataSourceAdapter"><rect codeline="6" fill="#F1F1F1" height="48" id="AbstractProducerToDataSourceAdapter" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="548" x="7" y="228"/><ellipse cx="22" cy="244" fill="#A9DCDF" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M24.0781,245.8125 L24.4688,246.7969 L24.0781,246.7969 C23.625,246.7969 23.5156,246.8125 23.3594,246.9219 C23.1094,247.0781 22.9531,247.3594 22.9531,247.6563 C22.9531,247.9219 23.0938,248.1719 23.3125,248.3281 C23.4531,248.4531 23.6563,248.5 24.0781,248.5 L26.4375,248.5 C26.7969,248.5 27.0156,248.4688 27.1563,248.375 C27.4063,248.2344 27.5625,247.9375 27.5625,247.6563 C27.5625,247.375 27.4219,247.125 27.2031,246.9688 C27.0313,246.8281 26.875,246.7969 26.4063,246.7969 L23.0156,238.5938 L19.3438,238.5938 C18.8906,238.5938 18.7656,238.6094 18.6094,238.7031 C18.3594,238.875 18.2031,239.1563 18.2031,239.4375 C18.2031,239.7188 18.3438,239.9688 18.5625,240.1406 C18.7344,240.25 18.9063,240.2813 19.3438,240.2813 L20.4219,240.2813 L17.7813,246.7969 C17.3594,246.7969 17.2031,246.8125 17.0469,246.9219 C16.7969,247.0781 16.6406,247.3594 16.6406,247.6563 C16.6406,248.2188 17.0156,248.5 17.7656,248.5 L20.0313,248.5 C20.3906,248.5 20.6094,248.4688 20.7344,248.375 C21,248.2344 21.1406,247.9375 21.1406,247.6563 C21.1406,247.375 21.0156,247.125 20.7969,246.9531 C20.625,246.8281 20.4844,246.7969 20.0313,246.7969 L19.6406,246.7969 L20.0313,245.8125 L24.0781,245.8125 Z M23.375,244.1094 L20.7031,244.1094 L22.0469,240.8438 L23.375,244.1094 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="282" x="36" y="248.8467">AbstractProducerToDataSourceAdapter</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="232" x="326" y="225"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="230" x="327" y="237.1387">CloseableReference&lt;CloseableImage&gt;</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="554" y1="260" y2="260"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="554" y1="268" y2="268"/></g><!--class CloseableProducerToDataSourceAdapter--><g id="elem_CloseableProducerToDataSourceAdapter"><rect codeline="7" fill="#F1F1F1" height="48" id="CloseableProducerToDataSourceAdapter" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="424" x="457" y="365"/><ellipse cx="472" cy="381" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M474.3438,376.6719 C473.4063,376.2344 472.8125,376.0938 471.9375,376.0938 C469.3125,376.0938 467.3125,378.1719 467.3125,380.8906 L467.3125,382.0156 C467.3125,384.5938 469.4219,386.4844 472.3125,386.4844 C473.5313,386.4844 474.6875,386.1875 475.4375,385.6406 C476.0156,385.2344 476.3438,384.7813 476.3438,384.3906 C476.3438,383.9375 475.9531,383.5469 475.4844,383.5469 C475.2656,383.5469 475.0625,383.625 474.875,383.8125 C474.4219,384.2969 474.4219,384.2969 474.2344,384.3906 C473.8125,384.6563 473.125,384.7813 472.3594,384.7813 C470.3125,384.7813 469.0156,383.6875 469.0156,381.9844 L469.0156,380.8906 C469.0156,379.1094 470.2656,377.7969 472,377.7969 C472.5781,377.7969 473.1875,377.9531 473.6563,378.2031 C474.1406,378.4844 474.3125,378.7031 474.4063,379.1094 C474.4688,379.5156 474.5,379.6406 474.6406,379.7656 C474.7813,379.9063 475.0156,380.0156 475.2344,380.0156 C475.5,380.0156 475.7656,379.875 475.9375,379.6563 C476.0469,379.5 476.0781,379.3125 476.0781,378.8906 L476.0781,377.4688 C476.0781,377.0313 476.0625,376.9063 475.9688,376.75 C475.8125,376.4844 475.5313,376.3438 475.2344,376.3438 C474.9375,376.3438 474.7344,376.4375 474.5156,376.75 L474.3438,376.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="294" x="486" y="385.8467">CloseableProducerToDataSourceAdapter</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="96" x="788" y="362"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="94" x="789" y="374.1387">CloseableImage</text><line style="stroke:#181818;stroke-width:0.5;" x1="458" x2="880" y1="397" y2="397"/><line style="stroke:#181818;stroke-width:0.5;" x1="458" x2="880" y1="405" y2="405"/></g><!--class DataSubscriber--><g id="elem_DataSubscriber"><rect codeline="13" fill="#F1F1F1" height="48" id="DataSubscriber" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="376" x="590" y="228"/><ellipse cx="605" cy="244" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M605.9531,240.7813 L607.6719,240.7813 C608.0625,240.7813 608.25,240.75 608.375,240.6719 C608.6406,240.5156 608.7813,240.2344 608.7813,239.9375 C608.7813,239.6719 608.6719,239.4063 608.4375,239.2344 C608.2656,239.125 608.125,239.0938 607.6719,239.0938 L602.5313,239.0938 C602.0938,239.0938 601.9688,239.1094 601.8125,239.2031 C601.5625,239.3594 601.4063,239.6563 601.4063,239.9375 C601.4063,240.2188 601.5469,240.4688 601.7656,240.6406 C601.9219,240.75 602.1094,240.7813 602.5313,240.7813 L604.25,240.7813 L604.25,247.2969 L602.5313,247.2969 C602.0938,247.2969 601.9688,247.3125 601.8125,247.4219 C601.5625,247.5781 601.4063,247.8594 601.4063,248.1563 C601.4063,248.4063 601.5469,248.6719 601.7656,248.8281 C601.9219,248.9531 602.125,249 602.5313,249 L607.6719,249 C608.4219,249 608.7813,248.7188 608.7813,248.1563 C608.7813,247.875 608.6719,247.625 608.4375,247.4531 C608.2656,247.3281 608.125,247.2969 607.6719,247.2969 L605.9531,247.2969 L605.9531,240.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="110" x="619" y="248.8467">DataSubscriber</text><rect fill="#FFFFFF" height="15.9688" style="stroke:#181818;stroke-width:1.0;stroke-dasharray:2.0,2.0;" width="232" x="737" y="225"/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacing" textLength="230" x="738" y="237.1387">CloseableReference&lt;CloseableImage&gt;</text><line style="stroke:#181818;stroke-width:0.5;" x1="591" x2="965" y1="260" y2="260"/><line style="stroke:#181818;stroke-width:0.5;" x1="591" x2="965" y1="268" y2="268"/></g><!--reverse link DataSource to AbstractDataSource--><g id="link_DataSource_AbstractDataSource"><path codeline="8" d="M653,76.217 C653,94.165 653,100.892 653,118.828 " fill="none" id="DataSource-backto-AbstractDataSource" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="653,58.217,647,76.217,659,76.217,653,58.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AbstractDataSource to AbstractProducerToDataSourceAdapter--><g id="link_AbstractDataSource_AbstractProducerToDataSourceAdapter"><path codeline="9" d="M555.4413,172.0615 C492.8593,190.0615 423.662,209.966 361.117,227.956 " fill="none" id="AbstractDataSource-backto-AbstractProducerToDataSourceAdapter" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="572.74,167.086,553.7828,166.2953,557.0998,177.8277,572.74,167.086" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AbstractProducerToDataSourceAdapter to CloseableProducerToDataSourceAdapter--><g id="link_AbstractProducerToDataSourceAdapter_CloseableProducerToDataSourceAdapter"><path codeline="10" d="M406.7091,280.351 C440.0571,288.553 459.151,294.381 492,306 C538.775,322.544 589.98,347.0071 625.226,364.9074 " fill="none" id="AbstractProducerToDataSourceAdapter-backto-CloseableProducerToDataSourceAdapter" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="389.23,276.052,405.2761,286.1774,408.1421,274.5247,389.23,276.052" style="stroke:#181818;stroke-width:1.0;"/></g><!--link AbstractProducerToDataSourceAdapter to Producer--><g id="link_AbstractProducerToDataSourceAdapter_Producer"><path codeline="11" d="M236.869,276.157 C226.12,284.084 215.998,294.037 210,306 C202.849,320.263 201.7812,331.7876 203.6842,346.9377 " fill="none" id="AbstractProducerToDataSourceAdapter-to-Producer" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="204.432,352.8909,207.2791,343.4625,203.8088,347.9299,199.3415,344.4596,204.432,352.8909" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="26" x="211" y="319.0669">&#20381;&#36182;</text></g><!--link AbstractProducerToDataSourceAdapter to Producer--><g id="link_AbstractProducerToDataSourceAdapter_Producer"><path codeline="12" d="M331.172,276.183 C361.05,292.931 396.466,318.65 414,353 C425.317,375.1714 445.893,409 421,409 " fill="none" id="AbstractProducerToDataSourceAdapter-to-Producer-1" style="stroke:#0000FF;stroke-width:1.0;stroke-dasharray:7.0,7.0;"/><polygon fill="#0000FF" points="415,409,424,413,420,409,424,405,415,409" style="stroke:#0000FF;stroke-width:1.0;"/><text fill="#0000FF" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="91" x="392" y="319.0669">&#26500;&#36896;&#20989;&#25968;&#20013;&#35843;&#29992;</text></g><!--reverse link AbstractDataSource to DataSubscriber--><g id="link_AbstractDataSource_DataSubscriber"><path codeline="14" d="M689.2392,175.0206 C710.2062,192.9686 729.976,209.892 750.93,227.828 " fill="none" id="AbstractDataSource-backto-DataSubscriber" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="680.123,167.217,682.0799,174.1575,689.2392,175.0206,687.2823,168.0801,680.123,167.217" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="677.7592" y="187.0311">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="734.9683" y="216.796">n</text></g><!--SRC=[Iyv9B2vMS4aiIGpEBorAJhLnpialJarCoaaDIarBBKhDGnRop4rCJxMpuqe6QmeeoayfJKuj8aQBGZMN0X2KvMUcA1H0z0Mb5fVcb1HhEEVd5PVc0eq9iTE1cmaKB4cjAD7agkLAJ2ekAKfCBb5mX398T2o6VfWT8Va8annJ4WjAYFCArFTmOQACW-ZbGgXGiAdHrSNY9IvC8LIbUApZ8a8Dn31Y74-KQRgwTl0uKx1IUB9lxekjqqZMQMM5cYOKb9DoIbEjSpBpKlLI4eipKbEiGQd12YGAjENPl9QN3GkUjkzzDdN3anrhNsneVZvb1LScCCKKfIK2mmjiMMbISN9HPXAHSOebr9KCbHIqW66bbAU4PY80]--></g></svg>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/863074da.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/fd3db9c4.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/fd3db9c4.html" class="post-title-link" itemprop="url">Java CAS详解</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-08-25 17:12:10" itemprop="dateCreated datePublished" datetime="2023-08-25T17:12:10+08:00">2023-08-25</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-09-02 11:24:55" itemprop="dateModified" datetime="2023-09-02T11:24:55+08:00">2023-09-02</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">介绍CAS实现原理</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="CAS介绍"><a href="#CAS介绍" class="headerlink" title="CAS介绍"></a>CAS介绍</h2><p>CAS(Compare and swap)是并发编程中经常用到的一项技术。大体上讲，CAS算法会先使用期望值比较变量的实际值，如果相同，就使用目标值替换变量的值。如果不相同，就会重新读取期望值再次进行对比和替换。</p>
<p>CAS主要是为了解决共享资源被加锁后，线程从阻塞状态切换回运行态比较耗时的问题，CAS是在不阻塞线程的情况下达到资源互斥的目的。但是如果共享资源竞争比较激烈就不适合使用CAS了，CAS会导致很多线程一直在重试访问共享资源，造成CPU资源的浪费。另外，如果共享资源的操作比较耗时，也就不适合使用CAS，这种场景使用阻塞的资源锁会更合适。</p>
<h2 id="CAS源码分析"><a href="#CAS源码分析" class="headerlink" title="CAS源码分析"></a>CAS源码分析</h2><p>以AtomicInteger.getAndIncrement为例进行源码分析，下面代码来自<a target="_blank" rel="noopener external nofollow noreferrer" href="https://hg.openjdk.org/jdk8/jdk8/jdk/">openJdk8源码</a>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">AtomicInteger</span> <span class="keyword">extends</span> <span class="title class_">Number</span> <span class="keyword">implements</span> <span class="title class_">java</span>.io.Serializable &#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">Unsafe</span> <span class="variable">unsafe</span> <span class="operator">=</span> Unsafe.getUnsafe();</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> <span class="type">long</span> valueOffset;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">static</span> &#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">//获取value变量地址</span></span><br><span class="line">            valueOffset = unsafe.objectFieldOffset</span><br><span class="line">                (AtomicInteger.class.getDeclaredField(<span class="string">&quot;value&quot;</span>));</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception ex) &#123; <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">Error</span>(ex); &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    ......</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">volatile</span> <span class="type">int</span> value; <span class="comment">//volatile类型的变量</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="type">int</span> <span class="title function_">getAndIncrement</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> unsafe.getAndAddInt(<span class="built_in">this</span>, valueOffset, <span class="number">1</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    ......</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><code>AtomicInteger.getAndIncrement</code>通过<code>Unsafe.getAndAddInt</code>方法实现：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/** Unsafe.java **/</span></span><br><span class="line">    <span class="comment">//native方法，通过jni来调用</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">native</span> <span class="type">boolean</span> <span class="title function_">compareAndSwapInt</span><span class="params">(Object o, <span class="type">long</span> offset,<span class="type">int</span> expected, <span class="type">int</span> x)</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="type">int</span> <span class="title function_">getAndAddInt</span><span class="params">(Object o, <span class="type">long</span> offset, <span class="type">int</span> delta)</span> &#123;</span><br><span class="line">        <span class="type">int</span> v;</span><br><span class="line">        <span class="keyword">do</span> &#123;</span><br><span class="line">            v = getIntVolatile(o, offset);</span><br><span class="line">        &#125; <span class="keyword">while</span> (!compareAndSwapInt(o, offset, v, v + delta));</span><br><span class="line">        <span class="keyword">return</span> v;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p><code>getAndAddInt</code>函数中，首先获取到期望值<code>v</code>，<code>v + delta</code>是目标值。然后进入compareAndSwapInt函数，compareAndSwapInt会首先对比实际值与期望值是否相同，如果相同就替换并返回true，while循环退出。如果不相同，compareAndSwapInt就返回false，继续执行while循环读取期望值，然后再次进行对比替换的步骤。</p>
<p><code>compareAndSwapInt</code>是native函数，源码在hotspot的<code>unsafe.cpp</code>文件中，在现在的系统中对比替换操作都是通过硬件机制来实现。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/fd3db9c4.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="https://rjyblog.gitee.io/posts/271b6343.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="Jason">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="任建勇的博客">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="undefined | 任建勇的博客">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/posts/271b6343.html" class="post-title-link" itemprop="url">Java线程池源码详解</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-08-23 15:59:34" itemprop="dateCreated datePublished" datetime="2023-08-23T15:59:34+08:00">2023-08-23</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-09-21 11:18:49" itemprop="dateModified" datetime="2023-09-21T11:18:49+08:00">2023-09-21</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

            <div class="post-description">Java线程池源码详解</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>线程池具备如下两个方面的优势：</p>
<ol>
<li>当需要创建大量异步任务时会改善应用性能，因为线程池减少了任务的调用开销；</li>
<li>可以更好的管理线程，比如监控线程使用情况、系统调优等；</li>
</ol>
<p>下面是线程池类图结构：</p>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="688px" preserveAspectRatio="none" style="width:380px;height:688px;background:#FFFFFF;" version="1.1" viewBox="0 0 380 688" width="380px" zoomAndPan="magnify"><defs/><g><!--class Executor--><g id="elem_Executor"><rect codeline="1" fill="#F1F1F1" height="64.2969" id="Executor" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="256" x="17" y="7"/><ellipse cx="109.25" cy="23" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M110.2031,19.7813 L111.9219,19.7813 C112.3125,19.7813 112.5,19.75 112.625,19.6719 C112.8906,19.5156 113.0313,19.2344 113.0313,18.9375 C113.0313,18.6719 112.9219,18.4063 112.6875,18.2344 C112.5156,18.125 112.375,18.0938 111.9219,18.0938 L106.7813,18.0938 C106.3438,18.0938 106.2188,18.1094 106.0625,18.2031 C105.8125,18.3594 105.6563,18.6563 105.6563,18.9375 C105.6563,19.2188 105.7969,19.4688 106.0156,19.6406 C106.1719,19.75 106.3594,19.7813 106.7813,19.7813 L108.5,19.7813 L108.5,26.2969 L106.7813,26.2969 C106.3438,26.2969 106.2188,26.3125 106.0625,26.4219 C105.8125,26.5781 105.6563,26.8594 105.6563,27.1563 C105.6563,27.4063 105.7969,27.6719 106.0156,27.8281 C106.1719,27.9531 106.375,28 106.7813,28 L111.9219,28 C112.6719,28 113.0313,27.7188 113.0313,27.1563 C113.0313,26.875 112.9219,26.625 112.6875,26.4531 C112.5156,26.3281 112.375,26.2969 111.9219,26.2969 L110.2031,26.2969 L110.2031,19.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="63" x="129.75" y="27.8467">Executor</text><line style="stroke:#181818;stroke-width:0.5;" x1="18" x2="272" y1="39" y2="39"/><line style="stroke:#181818;stroke-width:0.5;" x1="18" x2="272" y1="47" y2="47"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="244" x="23" y="63.9951">void execute(Runnable command)</text></g><!--class ExecutorService--><g id="elem_ExecutorService"><rect codeline="4" fill="#F1F1F1" height="96.8906" id="ExecutorService" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="276" x="7" y="132"/><ellipse cx="82.75" cy="148" fill="#B4A7E5" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M83.7031,144.7813 L85.4219,144.7813 C85.8125,144.7813 86,144.75 86.125,144.6719 C86.3906,144.5156 86.5313,144.2344 86.5313,143.9375 C86.5313,143.6719 86.4219,143.4063 86.1875,143.2344 C86.0156,143.125 85.875,143.0938 85.4219,143.0938 L80.2813,143.0938 C79.8438,143.0938 79.7188,143.1094 79.5625,143.2031 C79.3125,143.3594 79.1563,143.6563 79.1563,143.9375 C79.1563,144.2188 79.2969,144.4688 79.5156,144.6406 C79.6719,144.75 79.8594,144.7813 80.2813,144.7813 L82,144.7813 L82,151.2969 L80.2813,151.2969 C79.8438,151.2969 79.7188,151.3125 79.5625,151.4219 C79.3125,151.5781 79.1563,151.8594 79.1563,152.1563 C79.1563,152.4063 79.2969,152.6719 79.5156,152.8281 C79.6719,152.9531 79.875,153 80.2813,153 L85.4219,153 C86.1719,153 86.5313,152.7188 86.5313,152.1563 C86.5313,151.875 86.4219,151.625 86.1875,151.4531 C86.0156,151.3281 85.875,151.2969 85.4219,151.2969 L83.7031,151.2969 L83.7031,144.7813 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" font-style="italic" lengthAdjust="spacing" textLength="116" x="103.25" y="152.8467">ExecutorService</text><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="282" y1="164" y2="164"/><line style="stroke:#181818;stroke-width:0.5;" x1="8" x2="282" y1="172" y2="172"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="264" x="13" y="188.9951">Future&lt;?&gt; submit(Runnable task, ...)</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="113" x="13" y="205.292">void shutdown()</text><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="228" x="13" y="221.5889">List&lt;Runnable&gt; shutdownNow()</text></g><!--class AbstractExecutorService--><g id="elem_AbstractExecutorService"><rect fill="#F1F1F1" height="48" id="AbstractExecutorService" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="212" x="39" y="290"/><ellipse cx="54" cy="306" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M56.3438,301.6719 C55.4063,301.2344 54.8125,301.0938 53.9375,301.0938 C51.3125,301.0938 49.3125,303.1719 49.3125,305.8906 L49.3125,307.0156 C49.3125,309.5938 51.4219,311.4844 54.3125,311.4844 C55.5313,311.4844 56.6875,311.1875 57.4375,310.6406 C58.0156,310.2344 58.3438,309.7813 58.3438,309.3906 C58.3438,308.9375 57.9531,308.5469 57.4844,308.5469 C57.2656,308.5469 57.0625,308.625 56.875,308.8125 C56.4219,309.2969 56.4219,309.2969 56.2344,309.3906 C55.8125,309.6563 55.125,309.7813 54.3594,309.7813 C52.3125,309.7813 51.0156,308.6875 51.0156,306.9844 L51.0156,305.8906 C51.0156,304.1094 52.2656,302.7969 54,302.7969 C54.5781,302.7969 55.1875,302.9531 55.6563,303.2031 C56.1406,303.4844 56.3125,303.7031 56.4063,304.1094 C56.4688,304.5156 56.5,304.6406 56.6406,304.7656 C56.7813,304.9063 57.0156,305.0156 57.2344,305.0156 C57.5,305.0156 57.7656,304.875 57.9375,304.6563 C58.0469,304.5 58.0781,304.3125 58.0781,303.8906 L58.0781,302.4688 C58.0781,302.0313 58.0625,301.9063 57.9688,301.75 C57.8125,301.4844 57.5313,301.3438 57.2344,301.3438 C56.9375,301.3438 56.7344,301.4375 56.5156,301.75 L56.3438,301.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="180" x="68" y="310.8467">AbstractExecutorService</text><line style="stroke:#181818;stroke-width:0.5;" x1="40" x2="250" y1="322" y2="322"/><line style="stroke:#181818;stroke-width:0.5;" x1="40" x2="250" y1="330" y2="330"/></g><!--class ThreadPoolExecutor--><g id="elem_ThreadPoolExecutor"><rect fill="#F1F1F1" height="48" id="ThreadPoolExecutor" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="177" x="184.5" y="399"/><ellipse cx="199.5" cy="415" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M201.8438,410.6719 C200.9063,410.2344 200.3125,410.0938 199.4375,410.0938 C196.8125,410.0938 194.8125,412.1719 194.8125,414.8906 L194.8125,416.0156 C194.8125,418.5938 196.9219,420.4844 199.8125,420.4844 C201.0313,420.4844 202.1875,420.1875 202.9375,419.6406 C203.5156,419.2344 203.8438,418.7813 203.8438,418.3906 C203.8438,417.9375 203.4531,417.5469 202.9844,417.5469 C202.7656,417.5469 202.5625,417.625 202.375,417.8125 C201.9219,418.2969 201.9219,418.2969 201.7344,418.3906 C201.3125,418.6563 200.625,418.7813 199.8594,418.7813 C197.8125,418.7813 196.5156,417.6875 196.5156,415.9844 L196.5156,414.8906 C196.5156,413.1094 197.7656,411.7969 199.5,411.7969 C200.0781,411.7969 200.6875,411.9531 201.1563,412.2031 C201.6406,412.4844 201.8125,412.7031 201.9063,413.1094 C201.9688,413.5156 202,413.6406 202.1406,413.7656 C202.2813,413.9063 202.5156,414.0156 202.7344,414.0156 C203,414.0156 203.2656,413.875 203.4375,413.6563 C203.5469,413.5 203.5781,413.3125 203.5781,412.8906 L203.5781,411.4688 C203.5781,411.0313 203.5625,410.9063 203.4688,410.75 C203.3125,410.4844 203.0313,410.3438 202.7344,410.3438 C202.4375,410.3438 202.2344,410.4375 202.0156,410.75 L201.8438,410.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="145" x="213.5" y="419.8467">ThreadPoolExecutor</text><line style="stroke:#181818;stroke-width:0.5;" x1="185.5" x2="360.5" y1="431" y2="431"/><line style="stroke:#181818;stroke-width:0.5;" x1="185.5" x2="360.5" y1="439" y2="439"/></g><!--class Executors--><g id="elem_Executors"><rect fill="#F1F1F1" height="48" id="Executors" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="103" x="78.5" y="524"/><ellipse cx="93.5" cy="540" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M95.8438,535.6719 C94.9063,535.2344 94.3125,535.0938 93.4375,535.0938 C90.8125,535.0938 88.8125,537.1719 88.8125,539.8906 L88.8125,541.0156 C88.8125,543.5938 90.9219,545.4844 93.8125,545.4844 C95.0313,545.4844 96.1875,545.1875 96.9375,544.6406 C97.5156,544.2344 97.8438,543.7813 97.8438,543.3906 C97.8438,542.9375 97.4531,542.5469 96.9844,542.5469 C96.7656,542.5469 96.5625,542.625 96.375,542.8125 C95.9219,543.2969 95.9219,543.2969 95.7344,543.3906 C95.3125,543.6563 94.625,543.7813 93.8594,543.7813 C91.8125,543.7813 90.5156,542.6875 90.5156,540.9844 L90.5156,539.8906 C90.5156,538.1094 91.7656,536.7969 93.5,536.7969 C94.0781,536.7969 94.6875,536.9531 95.1563,537.2031 C95.6406,537.4844 95.8125,537.7031 95.9063,538.1094 C95.9688,538.5156 96,538.6406 96.1406,538.7656 C96.2813,538.9063 96.5156,539.0156 96.7344,539.0156 C97,539.0156 97.2656,538.875 97.4375,538.6563 C97.5469,538.5 97.5781,538.3125 97.5781,537.8906 L97.5781,536.4688 C97.5781,536.0313 97.5625,535.9063 97.4688,535.75 C97.3125,535.4844 97.0313,535.3438 96.7344,535.3438 C96.4375,535.3438 96.2344,535.4375 96.0156,535.75 L95.8438,535.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="71" x="107.5" y="544.8467">Executors</text><line style="stroke:#181818;stroke-width:0.5;" x1="79.5" x2="180.5" y1="556" y2="556"/><line style="stroke:#181818;stroke-width:0.5;" x1="79.5" x2="180.5" y1="564" y2="564"/></g><!--class ForkJoinPool--><g id="elem_ForkJoinPool"><rect fill="#F1F1F1" height="48" id="ForkJoinPool" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="121" x="28.5" y="399"/><ellipse cx="43.5" cy="415" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M45.8438,410.6719 C44.9063,410.2344 44.3125,410.0938 43.4375,410.0938 C40.8125,410.0938 38.8125,412.1719 38.8125,414.8906 L38.8125,416.0156 C38.8125,418.5938 40.9219,420.4844 43.8125,420.4844 C45.0313,420.4844 46.1875,420.1875 46.9375,419.6406 C47.5156,419.2344 47.8438,418.7813 47.8438,418.3906 C47.8438,417.9375 47.4531,417.5469 46.9844,417.5469 C46.7656,417.5469 46.5625,417.625 46.375,417.8125 C45.9219,418.2969 45.9219,418.2969 45.7344,418.3906 C45.3125,418.6563 44.625,418.7813 43.8594,418.7813 C41.8125,418.7813 40.5156,417.6875 40.5156,415.9844 L40.5156,414.8906 C40.5156,413.1094 41.7656,411.7969 43.5,411.7969 C44.0781,411.7969 44.6875,411.9531 45.1563,412.2031 C45.6406,412.4844 45.8125,412.7031 45.9063,413.1094 C45.9688,413.5156 46,413.6406 46.1406,413.7656 C46.2813,413.9063 46.5156,414.0156 46.7344,414.0156 C47,414.0156 47.2656,413.875 47.4375,413.6563 C47.5469,413.5 47.5781,413.3125 47.5781,412.8906 L47.5781,411.4688 C47.5781,411.0313 47.5625,410.9063 47.4688,410.75 C47.3125,410.4844 47.0313,410.3438 46.7344,410.3438 C46.4375,410.3438 46.2344,410.4375 46.0156,410.75 L45.8438,410.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="89" x="57.5" y="419.8467">ForkJoinPool</text><line style="stroke:#181818;stroke-width:0.5;" x1="29.5" x2="148.5" y1="431" y2="431"/><line style="stroke:#181818;stroke-width:0.5;" x1="29.5" x2="148.5" y1="439" y2="439"/></g><!--class Worker--><g id="elem_Worker"><rect fill="#F1F1F1" height="48" id="Worker" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="85" x="230.5" y="524"/><ellipse cx="245.5" cy="540" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M247.8438,535.6719 C246.9063,535.2344 246.3125,535.0938 245.4375,535.0938 C242.8125,535.0938 240.8125,537.1719 240.8125,539.8906 L240.8125,541.0156 C240.8125,543.5938 242.9219,545.4844 245.8125,545.4844 C247.0313,545.4844 248.1875,545.1875 248.9375,544.6406 C249.5156,544.2344 249.8438,543.7813 249.8438,543.3906 C249.8438,542.9375 249.4531,542.5469 248.9844,542.5469 C248.7656,542.5469 248.5625,542.625 248.375,542.8125 C247.9219,543.2969 247.9219,543.2969 247.7344,543.3906 C247.3125,543.6563 246.625,543.7813 245.8594,543.7813 C243.8125,543.7813 242.5156,542.6875 242.5156,540.9844 L242.5156,539.8906 C242.5156,538.1094 243.7656,536.7969 245.5,536.7969 C246.0781,536.7969 246.6875,536.9531 247.1563,537.2031 C247.6406,537.4844 247.8125,537.7031 247.9063,538.1094 C247.9688,538.5156 248,538.6406 248.1406,538.7656 C248.2813,538.9063 248.5156,539.0156 248.7344,539.0156 C249,539.0156 249.2656,538.875 249.4375,538.6563 C249.5469,538.5 249.5781,538.3125 249.5781,537.8906 L249.5781,536.4688 C249.5781,536.0313 249.5625,535.9063 249.4688,535.75 C249.3125,535.4844 249.0313,535.3438 248.7344,535.3438 C248.4375,535.3438 248.2344,535.4375 248.0156,535.75 L247.8438,535.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="53" x="259.5" y="544.8467">Worker</text><line style="stroke:#181818;stroke-width:0.5;" x1="231.5" x2="314.5" y1="556" y2="556"/><line style="stroke:#181818;stroke-width:0.5;" x1="231.5" x2="314.5" y1="564" y2="564"/></g><!--class Thread--><g id="elem_Thread"><rect fill="#F1F1F1" height="48" id="Thread" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="82" x="291" y="633"/><ellipse cx="306" cy="649" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M308.3438,644.6719 C307.4063,644.2344 306.8125,644.0938 305.9375,644.0938 C303.3125,644.0938 301.3125,646.1719 301.3125,648.8906 L301.3125,650.0156 C301.3125,652.5938 303.4219,654.4844 306.3125,654.4844 C307.5313,654.4844 308.6875,654.1875 309.4375,653.6406 C310.0156,653.2344 310.3438,652.7813 310.3438,652.3906 C310.3438,651.9375 309.9531,651.5469 309.4844,651.5469 C309.2656,651.5469 309.0625,651.625 308.875,651.8125 C308.4219,652.2969 308.4219,652.2969 308.2344,652.3906 C307.8125,652.6563 307.125,652.7813 306.3594,652.7813 C304.3125,652.7813 303.0156,651.6875 303.0156,649.9844 L303.0156,648.8906 C303.0156,647.1094 304.2656,645.7969 306,645.7969 C306.5781,645.7969 307.1875,645.9531 307.6563,646.2031 C308.1406,646.4844 308.3125,646.7031 308.4063,647.1094 C308.4688,647.5156 308.5,647.6406 308.6406,647.7656 C308.7813,647.9063 309.0156,648.0156 309.2344,648.0156 C309.5,648.0156 309.7656,647.875 309.9375,647.6563 C310.0469,647.5 310.0781,647.3125 310.0781,646.8906 L310.0781,645.4688 C310.0781,645.0313 310.0625,644.9063 309.9688,644.75 C309.8125,644.4844 309.5313,644.3438 309.2344,644.3438 C308.9375,644.3438 308.7344,644.4375 308.5156,644.75 L308.3438,644.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="50" x="320" y="653.8467">Thread</text><line style="stroke:#181818;stroke-width:0.5;" x1="292" x2="372" y1="665" y2="665"/><line style="stroke:#181818;stroke-width:0.5;" x1="292" x2="372" y1="673" y2="673"/></g><!--class Runnable--><g id="elem_Runnable"><rect fill="#F1F1F1" height="48" id="Runnable" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="99" x="48.5" y="633"/><ellipse cx="63.5" cy="649" fill="#ADD1B2" rx="11" ry="11" style="stroke:#181818;stroke-width:1.0;"/><path d="M65.8438,644.6719 C64.9063,644.2344 64.3125,644.0938 63.4375,644.0938 C60.8125,644.0938 58.8125,646.1719 58.8125,648.8906 L58.8125,650.0156 C58.8125,652.5938 60.9219,654.4844 63.8125,654.4844 C65.0313,654.4844 66.1875,654.1875 66.9375,653.6406 C67.5156,653.2344 67.8438,652.7813 67.8438,652.3906 C67.8438,651.9375 67.4531,651.5469 66.9844,651.5469 C66.7656,651.5469 66.5625,651.625 66.375,651.8125 C65.9219,652.2969 65.9219,652.2969 65.7344,652.3906 C65.3125,652.6563 64.625,652.7813 63.8594,652.7813 C61.8125,652.7813 60.5156,651.6875 60.5156,649.9844 L60.5156,648.8906 C60.5156,647.1094 61.7656,645.7969 63.5,645.7969 C64.0781,645.7969 64.6875,645.9531 65.1563,646.2031 C65.6406,646.4844 65.8125,646.7031 65.9063,647.1094 C65.9688,647.5156 66,647.6406 66.1406,647.7656 C66.2813,647.9063 66.5156,648.0156 66.7344,648.0156 C67,648.0156 67.2656,647.875 67.4375,647.6563 C67.5469,647.5 67.5781,647.3125 67.5781,646.8906 L67.5781,645.4688 C67.5781,645.0313 67.5625,644.9063 67.4688,644.75 C67.3125,644.4844 67.0313,644.3438 66.7344,644.3438 C66.4375,644.3438 66.2344,644.4375 66.0156,644.75 L65.8438,644.6719 Z " fill="#000000"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="67" x="77.5" y="653.8467">Runnable</text><line style="stroke:#181818;stroke-width:0.5;" x1="49.5" x2="146.5" y1="665" y2="665"/><line style="stroke:#181818;stroke-width:0.5;" x1="49.5" x2="146.5" y1="673" y2="673"/></g><g id="elem_GMN21"><path d="M182.5,644.5 L182.5,653 L147.629,657 L182.5,661 L182.5,669.6328 A0,0 0 0 0 182.5,669.6328 L255.5,669.6328 A0,0 0 0 0 255.5,669.6328 L255.5,654.5 L245.5,644.5 L182.5,644.5 A0,0 0 0 0 182.5,644.5 " fill="#FEFFDD" style="stroke:#181818;stroke-width:0.5;"/><path d="M245.5,644.5 L245.5,654.5 L255.5,654.5 L245.5,644.5 " fill="#FEFFDD" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="52" x="188.5" y="661.5669">&#29992;&#25143;&#20219;&#21153;</text></g><!--reverse link Executor to ExecutorService--><g id="link_Executor_ExecutorService"><path codeline="9" d="M145,89.307 C145,107.14 145,111.849 145,131.853 " fill="none" id="Executor-backto-ExecutorService" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="145,71.307,139,89.307,151,89.307,145,71.307" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ExecutorService to AbstractExecutorService--><g id="link_ExecutorService_AbstractExecutorService"><path codeline="10" d="M145,247.347 C145,267.909 145,272.999 145,289.703 " fill="none" id="ExecutorService-backto-AbstractExecutorService" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="145,229.347,139,247.347,151,247.347,145,229.347" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link AbstractExecutorService to ThreadPoolExecutor--><g id="link_AbstractExecutorService_ThreadPoolExecutor"><path codeline="11" d="M186.5841,349.7617 C208.0541,367.7097 223.824,380.892 245.28,398.828 " fill="none" id="AbstractExecutorService-backto-ThreadPoolExecutor" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="172.774,338.217,182.7359,354.3651,190.4324,345.1583,172.774,338.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ThreadPoolExecutor to Executors--><g id="link_ThreadPoolExecutor_Executors"><path codeline="12" d="M241.5543,451.0477 C215.9883,473.0387 182.303,502.012 156.777,523.968 " fill="none" id="ThreadPoolExecutor-backto-Executors" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="246.103,447.135,236.6714,449.9715,242.3124,450.3956,241.8883,456.0365,246.103,447.135" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="27" x="212" y="490.0669">new</text></g><!--reverse link ForkJoinPool to Executors--><g id="link_ForkJoinPool_Executors"><path codeline="13" d="M98.6091,452.8271 C105.9392,474.8181 115.004,502.012 122.323,523.968 " fill="none" id="ForkJoinPool-backto-Executors" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="96.7118,447.135,95.763,456.9381,98.2929,451.8784,103.3525,454.4083,96.7118,447.135" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="27" x="113" y="490.0669">new</text></g><!--reverse link AbstractExecutorService to ForkJoinPool--><g id="link_AbstractExecutorService_ForkJoinPool"><path codeline="14" d="M124.5027,354.165 C115.1097,372.113 110.515,380.892 101.1275,398.828 " fill="none" id="AbstractExecutorService-backto-ForkJoinPool" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="none" points="132.849,338.217,119.1867,351.3829,129.8187,356.9471,132.849,338.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Worker to Thread--><g id="link_Worker_Thread"><path codeline="15" d="M291.5961,582.7255 C301.4921,600.6734 309.333,614.8918 319.223,632.8279 " fill="none" id="Worker-backto-Thread" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="285.802,572.217,285.1962,579.4026,291.5961,582.7255,292.2019,575.5399,285.802,572.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link Worker to Runnable--><g id="link_Worker_Runnable"><path codeline="16" d="M224.7901,578.4768 C195.4361,596.4247 165.233,614.8918 135.898,632.8279 " fill="none" id="Worker-backto-Runnable" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="235.028,572.217,227.8224,571.9342,224.7901,578.4768,231.9956,578.7595,235.028,572.217" style="stroke:#181818;stroke-width:1.0;"/></g><!--reverse link ThreadPoolExecutor to Worker--><g id="link_ThreadPoolExecutor_Worker"><path codeline="18" d="M273,459.135 C273,481.126 273,502.012 273,523.968 " fill="none" id="ThreadPoolExecutor-backto-Worker" style="stroke:#181818;stroke-width:1.0;"/><polygon fill="#181818" points="273,447.135,269,453.135,273,459.135,277,453.135,273,447.135" style="stroke:#181818;stroke-width:1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="8" x="264.025" y="466.9291">1</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="26" x="243.6688" y="512.9718">0~n</text></g><!--SRC=[VP0zJiD048NxFSN8bOEm1IsoZ2X8WH12W4IzjYTubNW7xSx6IFpKY9eBq743Ybo7dsl4iR4JEJ_RpPjltdjQfHdDIAO8fm-OEYO3ZmAgDoML0TOQ-bTEQvbC458g2gcpWNWMQkto6irKLNDZC7Ji34R7CLYN58gN9YpjU1_2C1miaspkEADI-urshYn7xK7SRI-ez1VPNTVeAGZw-QBVfuPE4ij6fjo7j-ZDqKrkK6QNH9DstPbR2Dnz46z0u0WqbclWaCpuZ9HUeF_8pknLNjnM0nhOwpgjAkq_2KsCODHTpa2ZJgx2_ju_Vr-_lcUpdxSFiQ6nT-ZLJjx1Y_QWiPu3]--></g></svg>

<p>线程池分了两个大类：ThreadPoolExecutor是普通线程池，ForkJoinPool可用理解为是一个轻量级任务的线程池。</p>
<h2 id="线程池线程数量管理"><a href="#线程池线程数量管理" class="headerlink" title="线程池线程数量管理"></a>线程池线程数量管理</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="title function_">ThreadPoolExecutor</span><span class="params">(<span class="type">int</span> corePoolSize,</span></span><br><span class="line"><span class="params">                          <span class="type">int</span> maximumPoolSize,</span></span><br><span class="line"><span class="params">                          <span class="type">long</span> keepAliveTime,</span></span><br><span class="line"><span class="params">                          TimeUnit unit,</span></span><br><span class="line"><span class="params">                          BlockingQueue&lt;Runnable&gt; workQueue,</span></span><br><span class="line"><span class="params">                          ThreadFactory threadFactory,</span></span><br><span class="line"><span class="params">                          RejectedExecutionHandler handler)</span></span><br></pre></td></tr></table></figure>

<ol>
<li>corePoolSize核心线程数: 当线程池的线程数小于corePoolSize时，会创建一个新的线程来执行新任务，即使有线程处于闲置状态。</li>
<li>maximumPoolSize最大线程数：当线程数已经大于corePoolSize，新任务会被优先添加到队列中等待执行。如果任务队列满了导致添加失败，并且线程数小于maximumPoolSize，就会创建新的线程来执行新任务。大于核心线程数的这些线程算是“借”来的，当借来的这些线程的idle时间超过keepAliveTime，就会被回收。回收逻辑在runWorker函数中。</li>
<li>如果线程队列满了，线程数也已经大于maximumPoolSize，就会回调<code>RejectedExecutionHandler.rejectedExecution</code>让调用中来处理任务。</li>
</ol>
<?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentstyletype="text/css" height="228px" preserveAspectRatio="none" style="width:580px;height:228px;background:#FFFFFF;" version="1.1" viewBox="0 0 580 228" width="580px" zoomAndPan="magnify"><defs/><g><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="80" x="237" y="11"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="60" x="247" y="32.1387">&#28155;&#21152;&#26032;&#20219;&#21153;</text><polygon fill="#F1F1F1" points="48,64.9688,114,64.9688,126,76.9688,114,88.9688,48,88.9688,36,76.9688,48,64.9688" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="85" y="99.1792">no</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="66" x="48" y="80.7769">&#26680;&#24515;&#32447;&#31243;&#24050;&#28385;</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="140" x="11" y="121.7734"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="120" x="21" y="142.9121">&#21019;&#24314;&#26680;&#24515;&#32447;&#31243;&#25191;&#34892;&#20219;&#21153;</text><polygon fill="#F1F1F1" points="194,64.9688,260,64.9688,272,76.9688,260,88.9688,194,88.9688,182,76.9688,194,64.9688" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="231" y="99.1792">no</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="66" x="194" y="80.7769">&#20219;&#21153;&#38431;&#21015;&#24050;&#28385;</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="161" y="74.3745">yes</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="128" x="163" y="121.7734"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="108" x="173" y="142.9121">&#28155;&#21152;&#21040;&#38431;&#21015;&#31561;&#24453;&#25191;&#34892;</text><polygon fill="#F1F1F1" points="357.5,64.9688,434.5,64.9688,446.5,76.9688,434.5,88.9688,357.5,88.9688,345.5,76.9688,357.5,64.9688" style="stroke:#181818;stroke-width:0.5;"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="14" x="400" y="99.1792">no</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="77" x="357.5" y="80.7769">&#36798;&#21040;&#26368;&#22823;&#32447;&#31243;&#25968;</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="324.5" y="74.3745">yes</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacing" textLength="21" x="446.5" y="74.3745">yes</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="128" x="332" y="121.7734"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="108" x="342" y="142.9121">&#21019;&#26032;&#26032;&#32447;&#31243;&#25191;&#34892;&#20219;&#21153;</text><rect fill="#F1F1F1" height="33.9688" rx="12.5" ry="12.5" style="stroke:#181818;stroke-width:0.5;" width="92" x="477.5" y="118.3711"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacing" textLength="72" x="487.5" y="139.5098">&#25191;&#34892;&#25298;&#32477;&#31574;&#30053;</text><ellipse cx="277" cy="206.7422" fill="none" rx="11" ry="11" style="stroke:#222222;stroke-width:1.0;"/><ellipse cx="277" cy="206.7422" fill="#222222" rx="6" ry="6" style="stroke:#222222;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="81" x2="81" y1="88.9688" y2="121.7734"/><polygon fill="#181818" points="77,111.7734,81,121.7734,85,111.7734,81,115.7734" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="81" x2="81" y1="155.7422" y2="175.7422"/><polygon fill="#181818" points="77,165.7422,81,175.7422,85,165.7422,81,169.7422" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="227" x2="227" y1="88.9688" y2="121.7734"/><polygon fill="#181818" points="223,111.7734,227,121.7734,231,111.7734,227,115.7734" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="227" x2="227" y1="155.7422" y2="175.7422"/><polygon fill="#181818" points="223,165.7422,227,175.7422,231,165.7422,227,169.7422" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="396" x2="396" y1="88.9688" y2="121.7734"/><polygon fill="#181818" points="392,111.7734,396,121.7734,400,111.7734,396,115.7734" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="396" x2="396" y1="155.7422" y2="175.7422"/><polygon fill="#181818" points="392,165.7422,396,175.7422,400,165.7422,396,169.7422" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="126" x2="182" y1="76.9688" y2="76.9688"/><polygon fill="#181818" points="172,72.9688,182,76.9688,172,80.9688,176,76.9688" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="272" x2="345.5" y1="76.9688" y2="76.9688"/><polygon fill="#181818" points="335.5,72.9688,345.5,76.9688,335.5,80.9688,339.5,76.9688" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="277" x2="277" y1="44.9688" y2="49.9688"/><line style="stroke:#181818;stroke-width:1.0;" x1="277" x2="81" y1="49.9688" y2="49.9688"/><line style="stroke:#181818;stroke-width:1.0;" x1="81" x2="81" y1="49.9688" y2="64.9688"/><polygon fill="#181818" points="77,54.9688,81,64.9688,85,54.9688,81,58.9688" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="446.5" x2="523.5" y1="76.9688" y2="76.9688"/><line style="stroke:#181818;stroke-width:1.0;" x1="523.5" x2="523.5" y1="76.9688" y2="118.3711"/><polygon fill="#181818" points="519.5,108.3711,523.5,118.3711,527.5,108.3711,523.5,112.3711" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="523.5" x2="523.5" y1="152.3398" y2="175.7422"/><polygon fill="#181818" points="519.5,165.7422,523.5,175.7422,527.5,165.7422,523.5,169.7422" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="81" x2="523.5" y1="175.7422" y2="175.7422"/><line style="stroke:#181818;stroke-width:1.0;" x1="277" x2="277" y1="175.7422" y2="195.7422"/><polygon fill="#181818" points="273,185.7422,277,195.7422,281,185.7422,277,189.7422" style="stroke:#181818;stroke-width:1.0;"/><!--SRC=[itgsVVVJhWNFfcruiXl8M6ZDbPcceF5imOwd-vkVxzh_V4Ntq-sRdkrUgAbGaf6Qfw2Hbw_9fQ1WzRHZzjFTkv2LFUjS_c9X3ymGZShKOas5r9pYL91n4D6NC-O_xPYER1pCD8WRddPiW2XvlhRpwRvMY87eHhtOjm-exjcSXgTBbaCjdhe1rJIWsu3U0I9i3WEPem0s4cmnMEvPzwJdk-S-Nplj-TIbG1LvAPbfNCKb-GK0]--></g></svg>

<p><strong>通过一段代码测试一下上述线程数量的限制：</strong></p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/posts/271b6343.html#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" title="上一页" aria-label="上一页" href="/page/2/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><a class="page-number" href="/page/2/">2</a><span class="page-number current">3</span><a class="page-number" href="/page/4/">4</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" title="下一页" aria-label="下一页" href="/page/4/"><i class="fa fa-angle-right"></i></a>
  </nav>

</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Jason</span>
  </div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener external nofollow noreferrer" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener external nofollow noreferrer" target="_blank">NexT.Pisces</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.24/fancybox/fancybox.umd.js" integrity="sha256-oyhjPiYRWGXaAt+ny/mTMWOnN1GBoZDUQnzzgC7FRI4=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>


  <script class="next-config" data-name="mermaid" type="application/json">{"enable":true,"theme":{"light":"default","dark":"dark"},"js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.5.0/mermaid.min.js","integrity":"sha256-K7oJiQlDulzl24ZUFOywuYme1JqBBvQzK6m8qHjt9Gk="}}</script>
  <script type="module" src="/js/zenuml-definition-074a43fa.js"></script>
  <script type="module" src="/js/mermaid-zenuml.esm.min.mjs"></script>
  <script src="/js/third-party/tags/mermaid.js"></script>


  <script src="/js/third-party/fancybox.js"></script>



  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>



</body>
</html>
